remove text between delimiters, multiple times on each line

邮差的信 提交于 2019-12-02 03:14:41

问题


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


来源:https://stackoverflow.com/questions/55309712/remove-text-between-delimiters-multiple-times-on-each-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!