网上找到的 sed 命令和未知模式 [英] Sed command and unknown patterns found online

查看:49
本文介绍了网上找到的 sed 命令和未知模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要命令 sed 的帮助,尤其是以下表达式:

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

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

我知道 s/pattern/replacement/ 意味着 pattern 被替换为 replacement 并且当没有 时替换 意味着 模式 刚刚被删除(对吗?).另外,我在某处看到.*"匹配任何贪婪的东西,而[]"则匹配任何它的内容......我想.

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?

推荐答案

通过 cat 文件 |grep From: 并将输出传递到上面的 sed 表达式中,我可以看到它没有任何结果.所以我决定研究代码本身.我知道 .* 匹配任何贪婪的东西,并且 /// 是分隔符(from-to),我注意到最后一个块,s/.*[:<]*//,什么也没做.所以我把它拿走了.我还注意到第二个块 s/>.*// 将最后一个 ">" 从 From: Name Surname 中取出code>,所以我处理了第一个块,s/*(.*)//,使它能够擦除初始的<"以及它之前的任何东西.我结束了表达式 sed -e 's/.*<//;s/>.*//' 转换 From: Name Surname <name.surname@somedomain>name.surname@somedomain.

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.

这篇关于网上找到的 sed 命令和未知模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆