Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...