且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 sed,在字符第一次出现之前删除所有内容

更新时间:2022-12-28 11:18:31

通常,sed 中的量词是贪婪的,这就是为什么你总是匹配最后一个 =.定义第一个=的是它之前的所有字符都不是=,所以:

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/^[^=:]*[=:]//'