Reputation: 21
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
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