grep匹配tab

本文介绍了如何使用grep命令来匹配Tab键,提供了三种有效的方法:使用Perl兼容的正则表达式(-P选项),利用awk命令,或者直接插入Tab字符。这些方法适用于不同场景,并考虑了跨平台的适用性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天给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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值