I would like to identify every line with a specific string, in this case: "Mamma".
I would like to remove that line, and also the line above it and below it. So the below
Where are all amazing Flats
Look At The Great Big White
Hey There Hot Mamma
You Are So hot Baby
I wish You were Mine
Hee How Yee Haw
Hey There Hot Mamma
Wait A minute
Hee Haw Yee Haw
Hey There Hot Mamma
A song Is Here
Make me a List
Becomes
Where are all amazing Flats
I wish You were Mine
Make me a List
I was wondering if anyone could help me out? I've googled but it is a little complex for Google
---------- Post updated at 05:14 PM ---------- Previous update was at 05:07 PM ----------
I think this might work
sed -n '/Mamma/{N;s/.*//;x;d;};x;p;${x;p;}' file | sed '/^$/d'
$ ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian 5.0.8 (lenny, workstation)
bash GNU bash 3.2.39
column - ( /usr/bin/column, 2007-11-20 )
cgrep ATT cgrep 8.15
-----
Input data file data1 (columnized):
Where are all amazing Flats Hey There Hot Mamma
Look At The Great Big White Wait A minute
Hey There Hot Mamma Hee Haw Yee Haw
You Are So hot Baby Hey There Hot Mamma
I wish You were Mine A song Is Here
Hee How Yee Haw Make me a List
-----
Results:
Where are all amazing Flats
I wish You were Mine
Make me a List
The cgrep code is at the URL noted in the script; it needs to be compiled.
Have I missed the point in trying to make it too simple?
# cat input_file
Where are all amazing Flats
Look At The Great Big White
Hey There Hot Mamma
You Are So hot Baby
I wish You were Mine
Hee How Yee Haw
Hey There Hot Mamma
Wait A minute
Hee Haw Yee Haw
Hey There Hot Mamma
A song Is Here
Make me a List
# grep -B1 Mamma input_file>/tmp/tfile$$
# cat /tmp/tfile$$
Look At The Great Big White
Hey There Hot Mamma
--
Hee How Yee Haw
Hey There Hot Mamma
--
Hee Haw Yee Haw
Hey There Hot Mamma
# grep -vf /tmp/tfile$$ input_file
Where are all amazing Flats
You Are So hot Baby
I wish You were Mine
Wait A minute
A song Is Here
Make me a List
#