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


当前回答

你可以打字 Grep \t foo 或

grep '\t' foo

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

其他回答

你可以打字 Grep \t foo 或

grep '\t' foo

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

如果使用GNU grep,你可以使用perl风格的regexp:

grep -P '\t' *

多次查找空格[[:space:]]*

grep[:太空 :]]*'.''.'

会发现这样的东西:

“账单”..

这些是单引号('),而不是双引号(")。这就是在grep中进行连接的方法。= -)

These alternative binary identification methods are totally functional. And, I really like the one's using awk, as I couldn't quite remember the syntaxic use with single binary chars. However, it should also be possible to assign a shell variable a value in a POSIX portable fashion (i.e. TAB=echo "@" | tr "\100" "\011"), and then employ it from there everywhere, in a POSIX portable fashion; as well (i.e grep "$TAB" filename). While this solution works well with TAB, it will also work well other binary chars, when another desired binary value is used in the assignment (instead of the value for the TAB character to 'tr').

下面是问Ubuntu的答案:

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