\1 是显示在第一个括号中的内容,在这里括号中匹配的是<[email protected]>中的[email protected] 所以\1 就是显示[email protected]
2010/6/19 listofx <[email protected]>: > On 五, 2010-06-18 at 22:33 +0800, Tusooa Zhu wrote: >> 在 星期五 18 6月 2010 02:06:57,listofx 写 >> 道: >> > 通常,邮件头中发件人有如下格式 >> > From: xxx yyy <[email protected]> >> > From: “xxx yyy” <[email protected]> >> > From: [email protected] >> > >> > 我想提取这样一行中的地址(只是 >> [email protected]),该如何进行? >> > >> > 我知道:如果不考虑第三种情况,采用<字 >> 符作为字段分隔符,使用cut或者awk就 >> > 很容易得到结果。 >> > >> > sed能做到吗? >> > 在发邮件的时候,我想到一个办法,还是想 >> 看看是否有别的方式。 >> >> sed -e 's/.*<\(.*\)>.*/\1/' > > 我在man sed中看到\1的解释,但是没有看懂。即使看到您的回复,动手操作了一 > 下,还是不明白\1的作用。 > …… > 我终于在手里的一本电子书中找到了相应信息。也许info sed中有解释(info sed > 的信息比man sed详细),但是个人真的不喜欢info,凡是按键和vi不一致的都不 > 习惯。 > 谢谢! > > 解释如下,放在这里说不定有用。 > The sed editor uses parentheses to define a substring component within the > substitution pattern. > You can then reference each substring component using a special character in > the replacement > pattern. The replacement character consists of a backslash and a number. The > number indicates > the position of the substring component. The sed editor assigns the first > component the character > \1, the second component the character \2, and so on. > > > > -- > ubuntu-zh mailing list > [email protected] > https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh > -- Ray Wang - Follow your dreams -- ubuntu-zh mailing list [email protected] https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh
