Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

Sed command and unknown patterns found online

I need help with the command sed, in particular with the following expression:

sed -e 's/*(.*)//;s/>.*//;s/.*[:<]*//'

I know that s/pattern/replacement/ means that a pattern is replaced by a replacement and when there is no replacement it means that the pattern is just removed (is that correct?). Also, I have seen somewhere that ".*" matches anything greedy and that "[ ]" is a match of any of whatever its content is....I think.

Can anybody help please? What do the patterns *(.*) or >.* or .*[:<]* mean?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

By cat file | grep From: and piping the output into the above sed expression, I could see that nothing came out of it. So I decided to look into the code itself. I knew that .* matches anything greedy and that / // are separators (from-to), I noticed that the final block, s/.*[:<]*//, did nothing. So I took it away. I also noticed that the second block, s/>.*//, was taking the final ">" away from From: Name Surname <name.surname@somedomain>, so I worked on the first block, s/*(.*)//, to make it so that it would erase the initial "<" and whatever is before it. I ended up with the expression sed -e 's/.*<//;s/>.*//' that transforms From: Name Surname <name.surname@somedomain> into name.surname@somedomain.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...