remove text between delimiters, multiple times on

2020-04-17 04:42发布

I need to remove text between the delimiters "<" and ">", but there are multiple instances of these on each line of my text file.

For example, I want to turn this:

person 1, person 2<email2@mail.com>, person 3<email3@mail.com>, person 4<email4@mail.com>`

Into this:

person 1, person 2, person 3, person 4  

I've tried to use a few things, including sed:

sed -e 's/<.*>//' filename.csv

but this removes everything between the first < and the last > giving the result person 1, person 2.

2条回答
神经病院院长
2楼-- · 2020-04-17 05:13

you can use a negated character class in your regex:

sed 's/<[^>]*>//g' filename.csv
查看更多
SAY GOODBYE
3楼-- · 2020-04-17 05:16

If you want to join the dark side, Perl lets you specify non-greedy wildcards with ?:

perl -pe 's/<.*?>//g' filename.csv
查看更多
登录 后发表回答