Reputation: 1
I have problem, I want to parse a log file, I want to print a line if the above line is containing a specific word,
for example
line 1 containing : aaa
line 2 containing : bbb
so, it will print out bbb
Upvotes: 0
Views: 451
Reputation: 5598
If you don't want the 'aaa' printed as well, you could use sed(1):
sed -n '/aaa/{n;p}'
Explanation:
-n don't print every line
/aaa/ when this pattern is matched, execute the block that follows
n advance to the next line
p print what's in the buffer
Upvotes: 0
Reputation: 780851
The -A n
option to grep
prints the next n
lines after the matching line.
grep -A 1 aaa logfile
Upvotes: 1