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.

3 Answers 3

2

I guess the easiest solutions then are:

Sed:

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

Awk:

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

These might work for you:

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

or

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

using gnu sed:

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

1
  • The termination's (;) not needed, is it?
    – Det
    Apr 11, 2013 at 1:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .