Replacing multiple line patterns with awk

Hi forum,

Can you please help me understand how to look for and replace the below pattern (containing line breaks) and return a new result?

Rules: Must match the 3 line pattern and return a 1 line result.

I have found solutions with sed, but it seems that sed installed in my system is very limited so its not working. Are there other programs can be used to accomplish this result?

===============================================================
===============================================================
= Exit

Desired:

= Exit

Appreciate the help.

sed? What is the pattern on the third line? Otherwise try something like:

sed -n '/===/{N;/===.*\n===/{n;p;};}' file
1 Like

try this perl solution instead of sed... will depend on the exact pattern..

 
 perl -0pe 's/===============================================================\n===============================================================\n= Exit/= Exit/g' file
 
1 Like

This should work with all sed:

sed '
/^====================/ {
N;/\n====================/ {
N;s/.*\n= Exit/= Exit/
}
}
' file
1 Like

This one returned an error:

sed -n '/===/{N;/===.*\n===/{n;p;};}' file
sed: There are too many '{'.

Other 2 options worked fine.

Thank you guys.

Yes, some older sed's (HPUX?) cannot handle semicolons and need newlines instead:

sed -n '
/===/ {
  N
  /===.*\n===/ {
    n
    p
  }
}
' file