How to remove lines before and after with awk / sed ?

Hi guys,

I need to remove the pattern (ID=180), one line before and four lines after.

Thanks.

Could you please be more descriptive on the pattern of your input file and what exactly your requirement is??

The file has multiple entries beginning with id, name, url, created, uniqueid visited.
I want to remove some entries (they are dead links). However I can't manage to delete the line above the Id field (#url).

grep -v "ID=180" <filename> > abc.txt # will print all lines that does not match the string "ID=180" and will direct them to abc.txt

You can use grep if your grep version supports the -A and -B option, otherwise:

awk '/ID=180/{c=4;next}
c--<0 && p{print p}
{p=$0}
END{print p}
' file
1 Like

That works fine. Thank you, Franklin52.