You're viewing a comment by Sheetal and its responses.

Sheetal Permalink
May 17, 2016, 06:23

Hi Jotne,

I have used the below command to search for a pattern and remove the 5 lines before and 7 lines after the pattern:

awk '/pattern/{for(x=NR-5;x<=NR+7;x++)d[x];}{a[NR]=$0}END{for(i=1;i<=NR;i++)if(!(i in d))print a[i]}' filename

This is working as expected.

But I was not clear on the logic used.

Would you be able to help me understand the logic?

Thanks,
Sheetal

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "0day_100": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.