Quantcast
Channel: Grep for multiple strings, show number of lines after one of the strings (but not the other) - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 4

Answer by Archemar for Grep for multiple strings, show number of lines after one of the strings (but not the other)

$
0
0

about awk code

awk '/string1/ {if ( c <= 0 ) c = 1;} /string2/ {c=5} { if (c-- > 0) print; }' file
  • do not cat ... | awk, awk can read file.
  • I rearrange test (if string1 is one line after string2, it interrupt printing in OP's solution)

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>