Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

migrated from stackoverflow.com Apr 11 '13 at 6:14

This question came from our site for professional and enthusiast programmers.

up vote 0 down vote accepted

I guess the easiest solutions then are:

Sed:

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

Awk:

awk '/string/ && !p {p++;next}1' file
share|improve this answer

These might work for you:

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

or

awk '/string/ && !p {p++;next}1' file
share|improve this answer

using gnu sed:

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

share|improve this answer
    
The termination's (;) not needed, is it? – Det Apr 11 '13 at 1:35

You must log in to answer this question.

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