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
I guess the easiest solutions then are:
Sed:
sed -i '0,/string/{//d}' file
Awk:
awk '/string/ && !p {p++;next}1' file
These might work for you:
sed 'x;/./{x;b};x;/string/{h;d}' file
or
awk '/string/ && !p {p++;next}1' file
using gnu sed:
sed '0,/MYSTRING/{//d;}' file # delete only the first match
-
The termination's (
;
) not needed, is it?– DetApr 11, 2013 at 1:35