in reply to get n lines before or after a pattern
Note you're output is not only showing 2 lines before the pattern, but also 1 line AFTER the pattern.
You don't need Perl for something that simple:
grep -B2 -A1 jack test.txt
UPDATE: Since the OP updated the original question, this approach is no longer valid. See my reply (Re^3: get n lines before a pattern) below.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: get n lines before a pattern
by darklord_999 (Acolyte) on Jul 25, 2012 at 14:55 UTC | |
by VinsWorldcom (Prior) on Jul 25, 2012 at 15:16 UTC |