这里我正在练习grep命令.Am,下面的grep条件不清楚它是如何工作的?
a_file:
boot
record
boots
process
broken
commands我试过以下命令:-
1. grep -A0 "boo" a_file
result:
boot
--
boots
2.grep -A1 "boo" a_file
result:
boot
record
boots
process
3.grep -A2 "boo" a_file
result:
boot
record
boots
process
broken
4.grep -A3 "boo" a_file
result:
boot
record
boots
process
broken
commands
Note:I had studied this grep command from terminal man grep.我的问题是:
1.What is the purpose of switch -A?
2.How the context lines are ordered for every numeric values (i.e 1,2,3)?发布于 2017-08-10 10:24:31
对于您的第一个问题,-A或-B非常有用,而您却欺骗了一个长而复杂的日志。您可以使用-A和-B选项查看日志中搜索模式后面和之前的更多细节,这也加快了调试效率。
对于您的第二个问题,来自src of grep的选项-A没有具体的限制。它的参数,即out_after,定义为src中的long int。
static intmax_t out_after; /* Lines of trailing context. */我假设要打印的拖线直到EOF或下一个匹配模式被击中为止(尾随线的计数将被重置)。
https://stackoverflow.com/questions/45605912
复制相似问题