1

Get N lines before a pattern

view story
linux-howto

http://www.unix.com – I need to print N lines before a pattern ERR-XXXXX . The grep around and before option is not working for me. input file Code: line 1 some text line 2 some other text line 3 ERR-12345 line 4 some more text line 5 some blah blah blah line 6 ERR-56789 n=1 Output Code: line 2 some other text line 3 ERR-12345 line 5 some blah blah blah line 6 ERR-56789 With awk , I am getting the NR , is it possible to print line NR-1 , NR-2 with AWK (HowTos)