Friday, September 13, 2013

Awk trick

Awk trick 2


>>-- 13 September 2013 --<<

To get the grep -A and Grep -B in the Aix box.

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".


Thanks
~ aks

No comments:

Post a Comment