Removing first line with pattern with _both_ awk and sed

1

Fairly easy. I'm looking for the simplest approaches in both sed and awk for removing the first line in a file that contains a specific string.

Det

Posted 2013-04-11T01:10:39.917

Reputation: 111

Answers

2

I guess the easiest solutions then are:

Sed:

sed -i '0,/string/{//d}' file

Awk:

awk '/string/ && !p {p++;next}1' file

user216280

Posted 2013-04-11T01:10:39.917

Reputation:

1

These might work for you:

sed 'x;/./{x;b};x;/string/{h;d}' file

or

awk '/string/ && !p {p++;next}1' file

potong

Posted 2013-04-11T01:10:39.917

Reputation: 141

0

using gnu sed:

sed '0,/MYSTRING/{//d;}' file # delete only the first match

vwvan

Posted 2013-04-11T01:10:39.917

Reputation: 101

The termination's (;) not needed, is it? – None – 2013-04-11T01:35:51.880