user5689562
user5689562

Reputation: 21

Find variable pattern match and delete line by sed

I have a variable pattern. And I want to match pattern in file and if pattern is matched then line should be deleted.

I tried with:

sed '/$pattern/d' file.txt

But it doesn't work.

Please give me guidence for the same.

Thanks.

Upvotes: 1

Views: 3321

Answers (1)

Marcel
Marcel

Reputation: 3258

Just do that:

sed /$pattern/d file.txt

The quotes were transforming your variable in a string. Then you need to remove that.

And if you need to to write the changes in the file, just add -i

sed -i /$pattern/d file.txt

Upvotes: 2

Related Questions