Reputation: 1
Let's say I have a text file with the following contents:
test
blablabla
test1
moreblabla
atest
blabla3
just*a*test
blabla14
test88
lastblabla
I want to delete ONLY the line that matches EXACTLY the string "test" and the line after it WITHOUT deleting the lines that contain the string "test" So in my case I want to delete just the first and second lines but not the rest.
The above file is just an example, the contents of the file varies just like the string.
All the examples I found with sed
only deal with deleting lines that just contain some string. I want to delete only the line that IS exactly that string.
Upvotes: 0
Views: 89
Reputation: 56935
Just add ^
and $
around the test
regex to anchor your match.
sed -e '/^test$/,+1d' path/to/file
Or you could do ^ *test *$
for a line containing 'test' possibly with spaces.
Upvotes: 4