今天给maildroprc做脚本,发现不知道怎么用grep来匹配tab键,--虽然‘/t’是正则表达式的常见写法。
google了一下关键字“grep匹配tab”,有两篇帖子问这个问题的,底下的回答都是设法绕开这个问题,比如用“.*”来匹配tab键,不着调,很不爽。
再google一下外文吧,关键字“grep tab”,搜到一篇帖子:
Robert Mark Bram wrote:
> > How about just using the actual tab character? I don't see any
> > indication that
> > grep is supposed to treat '/t' specially and it seems to behave that way
> > on linux,
> > too.
>
> I have read in many places that /t is a metacharacter for tab in regular
> expressions - but maybe that's only for sed, perl, awk etc...
> http://sitescooper.org/tao_regexps.html
Try "grep -P '/t'" to use perl-compatible regexps. Note that this is a
specific capability of GNU grep, so it will not be portable to systems
that use a different grep. It might be more portable to use "awk
'//t/'".
Or to insert a literal tab as others said.
Brian
回答得太好了:讲了三种方法: 1 grep -P '/t'; 2 awk '//t/' 3 ctl+v,tab;
本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/qixinkui/archive/2008/07/31/2746433.aspx