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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.