今天给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;
每种都可以
借此机会反思一下中国软件从业人员和国外的差距
记得之前我搜postfix的系统结构图,搜到的画得详尽透彻的图都是来自日本网站的。。。差距。。。,
还经常看到国外的一些甚至是中学教师的个人网站上精美的代码,我觉得中国大学教授有那水平的也不多。。。
怎么中国就这么少人踏实下来呢,地震后祈福祷告,奥运前热血沸腾的人倒很多,有屁用~。