aix:获取字符串前后的行

时间:2012-05-03 11:06:31

标签: unix aix

我正在使用AIX,我有一个字符串“没有进程来读取写入管道的数据”。我希望在此字符串前面输出2行和4行。 字符串在日志中出现的次数超过100次,我想输出,带有此字符串的日志中的最后一个结果

我尝试使用:

nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=2   a=4 s="There is no process to read data written to a pipe" File.log

此命令的输出是我获得上述字符串存在的所有100多个结果

-A number -B number命令在AIX中不起作用

1 个答案:

答案 0 :(得分:0)

如果您有GNU grep,则可以使用它而不是awk:

grep -B 2 -A 4 "There is no process to read data written to a pipe" File.log