在UNIX中的特定包含字线后打印行

时间:2013-07-15 04:11:13

标签: parsing unix printing line word

我有问题,我想解析一个日志文件,如果上面的行包含一个特定的单词,我想打印一行,

例如

line 1 containing : aaa

line 2 containing : bbb

所以,它会打印出bbb

2 个答案:

答案 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