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

Answer by Costas for Grep for multiple strings, show number of lines after...

Sed solution: sed -n '/string2/,+4{p;b;};/string1/p' file my sed also accept ~ instead of +

View Article



Answer by Archemar for Grep for multiple strings, show number of lines after...

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,...

View Article

Answer by heemayl for Grep for multiple strings, show number of lines after...

You can't do that using one go of grep. You need to use two grep instances : grep 'string1' file; grep -A 5 'string2' file If you want to run the second upon success of the first one : grep 'string1'...

View Article

Grep for multiple strings, show number of lines after one of the strings (but...

I would like to search a file for multiple strings and for one particular string, show the 5 lines following it as well. cat file | grep -e 'string1' -e 'string2' works of course, but I would like to...

View Article
Browsing latest articles
Browse All 4 View Live




Latest Images