0

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

例如

line 1 containing : aaa

line 2 containing : bbb

所以,它会打印出 bbb

4

2 回答 2

1

在匹配行之后打印下一行的-A n选项。grepn

grep -A 1 aaa logfile
于 2013-07-15T04:13:56.757 回答
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
于 2014-08-14T11:39:55.390 回答