using sed, remove everything before the first occurence of a character

寵の児 提交于 2020-02-21 13:45:12

问题


Let's say I have a line looking like this

Hello my first name is =Bart and my second is =Homer

How can I do if I want to get everything after the first = or : using sed?

In this example, I would like to get the result

Bart and my second is =Homer

I am using sed 's/.*[=:]//' right now but I get Homer as result (everything after the last = or :) and I would like to get everything after the first, and not the last = or :


回答1:


Normally, quantifiers in sed are greedy, which is why you will always match the last =. What defines the first = is that all the characters before it are not =, so:

sed 's/^[^=]*=//'

Your question implies that either : or = are valid markers, in which case

sed 's/^[^=:]*[=:]//'


来源:https://stackoverflow.com/questions/44003133/using-sed-remove-everything-before-the-first-occurence-of-a-character

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