0

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

icodebuster
  • 8,890
  • 7
  • 62
  • 65
rusa23
  • 1
  • 1
    http://stackoverflow.com/questions/7451423/grep-a1-how-to-show-only-next-line-after-the-matched-one may have what you need –  Jul 15 '13 at 04:14

2 Answers2

1

The -A n option to grep prints the next n lines after the matching line.

grep -A 1 aaa logfile
Barmar
  • 741,623
  • 53
  • 500
  • 612
0

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
Aryeh Leib Taurog
  • 5,370
  • 1
  • 42
  • 49