我有问题,我想解析一个日志文件,如果上面的行包含一个特定的单词,我想打印一行,
例如
line 1 containing : aaa
line 2 containing : bbb
所以,它会打印出bbb
答案 0 :(得分:1)
-A n
的{{1}}选项会在匹配的行后打印下一个grep
行。
n
答案 1 :(得分:0)
如果您不想打印'aaa',也可以使用sed(1):
sed -n '/aaa/{n;p}'
说明:
-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