Briston12
Briston12

Reputation: 377

Remove lines from file containing a substring

I need to remove some lines from a file. In specific I need to remove all lines containing the substring: export JAVA_HOME=/usr/lib/jvm

I tried:

sed -i -e "/export JAVA_HOME=\"\/usr\/lib\/jvm*/d" file

and

sed -i -e "/export JAVA_HOME=\"\/usr\/lib\/jvm/d" file

but those don't remove the line I have in the file that is:

export JAVA_HOME=/usr/lib/jvm/openjdk-8-amd64/jre/

Any help please? Thanks

Upvotes: 0

Views: 35

Answers (1)

Felix Kling
Felix Kling

Reputation: 817128

Remove the quotation mark from your pattern, since it doesn't appear in the line you want to remove:

sed -i -e "/export JAVA_HOME=\"\/usr\/lib\/jvm/d" file
#                            ^^ remove this

Upvotes: 1

Related Questions