Skip to main content
[Edit removed during grace period]
Source Link
pLumo
  • 23.2k
  • 2
  • 43
  • 70
Source Link
pLumo
  • 23.2k
  • 2
  • 43
  • 70

try this,

perl -0777 -pe 's/,([^\n,]*\n[^\n]*PRIMARY)/)$1/g' 

This will replace the last , with ) in lines before any line including PRIMARY.

Explanation

  • perl -0777 slurp whole file (read as one line)
  • s/search_pattern/replacement/g Substitute search pattern with replacement globally