如何在Unix平台上的文件中grep标签(\t) ?


当前回答

我用ksh

grep "[^I]" testfile

其他回答

答案更简单。编写grep并在引号中输入tab键,它至少在ksh中工作得很好

grep "  " *

你可以打字 Grep \t foo 或

grep '\t' foo

在文件foo中搜索制表符。您可能还可以使用其他转义代码,尽管我只测试了\n。虽然这相当耗时,而且不清楚为什么要这样做,但在zsh中,您还可以键入制表符,回到开头,grep并将制表符用引号括起来。

一个好的选择是使用sed。

sed -n '/\t/p' file

示例(工作在bash, sh, ksh, csh,..):

[~]$ cat testfile
12 3
1 4 abc
xa      c
        a       c\2
1 23

[~]$ sed -n '/\t/p' testfile 
xa      c
        a       c\2
[~]$ sed -n '/\ta\t/p' testfile
        a       c\2

(以下答案已根据评论中的建议进行了编辑。谢谢大家)

下面是问Ubuntu的答案:

告诉grep使用由Perl定义的正则表达式(Perl拥有 \t as tab): grep -P "\t" <文件名称> . grep "\t" <文件名称> . grep "\t 使用文字制表符: grep "^V<tab>" <文件名> . grep "^V<tab> 使用printf打印制表符: Grep "$(printf '\t')"<文件名>

使用gawk,将字段分隔符设置为TAB (\t)并检查字段的数量。如果多于1,则有/有制表符

awk -F"\t" 'NF>1' file