I'd like to delete two lines in a file, containing pattern aaa bbb ccc
.
I have used the following expression, which deletes the line containing
pattern aaa bbb ccc
and the line before.
$ sed -n '/aaa bbb ccc/{s/.*//;x;d;};x;p;${x;p;}' file.txt | sed '/^$/d'
This works for one file. It doesn't work for multiple files
$ for i in *.txt; do sed -n '/aaa bbb ccc/{s/.*//;x;d;};x;p;${x;p;}' "$i" | sed '/^$/d'; done
example file:
xxx
yyy
aaa bbb ccc
eee
fff
aaa bbb ccc
ggg
hhh
result file:
xxx
eee
ggg
hhh
GNU bash, version 4.2.25(1)-release (i686-pc-linux-gnu)
– xralf May 23 '17 at 08:26ed -s your_file <<< $',$g/aaa bbb ccc/-1,.d\nw'
– Valentin Bajrami May 23 '17 at 08:28