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.
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.
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
The termination's (
;
) not needed, is it? – None – 2013-04-11T01:35:51.880