remove text between delimiters, multiple times on

2020-04-17 04:43发布

问题:

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.

回答1:

you can use a negated character class in your regex:

sed 's/<[^>]*>//g' filename.csv


回答2:

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

perl -pe 's/<.*?>//g' filename.csv