我有问题,我想解析一个日志文件,如果上面的行包含特定的单词,我想打印一行,
例如
line 1 containing : aaa
line 2 containing : bbb
所以,它会打印出 bbb
在匹配行之后打印下一行的-A n
选项。grep
n
grep -A 1 aaa logfile
如果您不想同时打印 '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