|
nawk use
I found a command who prints x lines before and after a line who contain a searched string in a text file.
The command is :
-------------------
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="string" file1
...where "b" and "a" are the number of lines to print before and after string "s".
-------------------
It works very well but I can't understand the syntax, too difficult with "man nawk". Is that some one who will be able to comment this syntax ?
Thank's in advance, best regards and happy new year.
|