wmitchell
wmitchell

Reputation: 5735

Remove matching line and following line from file

I have the following in a file

######################

asd asd MISC/TEXT asd asd
data concering above line

bla bla bla SEARCH/TEXT bla bla bla
data concering above line

asd asd MISC/TEXT asd asd
data concering above line
#######################

How do I remove the line containing SEARCH/TEXT and the line following it?

EDIT - The block/paragraph is always two lines long

EDIT2 - Expanded example file for clarity

Upvotes: 2

Views: 481

Answers (1)

Kent
Kent

Reputation: 195059

EDIT:

since you said only one data line after the pattern line:

sed '/SEARCH\/TEXT/{N;d;}' yourFile

test

kent$  echo "######################
bla bla bla SEARCH/TEXT bla bla bla
data concering above line

asd asd MISC/TEXT asd asd
data concering above line
#######################"|sed '/SEARCH\/TEXT/{N;d;}'
######################

asd asd MISC/TEXT asd asd
data concering above line
#######################

EDIT2:

test with new example input:

kent$  echo "######################
dquote> 
dquote> asd asd MISC/TEXT asd asd
dquote> data concering above line
dquote> 
dquote> bla bla bla SEARCH/TEXT bla bla bla
dquote> data concering above line
dquote> 
dquote> asd asd MISC/TEXT asd asd
dquote> data concering above line
dquote> #######################"|sed '/SEARCH\/TEXT/{N;d;}'
######################

asd asd MISC/TEXT asd asd
data concering above line


asd asd MISC/TEXT asd asd
data concering above line
#######################

Upvotes: 3

Related Questions