开发者

sed: delete all lines in a file using sentinel values

开发者 https://www.devze.com 2023-03-22 23:35 出处:网络
I want to do an inclusive delete from a file that looks like the following: Some text Some text #$ Should be deleted

I want to do an inclusive delete from a file that looks like the following:

Some text
Some text
#$
Should be deleted
Should also be del开发者_Go百科eted
#$
More text

I want the file to read the following after sed is ran through it:

Some text
Some text
More text

the #$ values should be inclusively removed.

Can someone explain the sed command used to do this as well?


Try this:

sed -e '/^#\$/,/^#\$/d' file

The idea is to match from the first time you see #$ to the second time, and then delete it.

0

精彩评论

暂无评论...
验证码 换一张
取 消