Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grep 省略长度不正确的行_Grep - Fatal编程技术网

Grep 省略长度不正确的行

Grep 省略长度不正确的行,grep,Grep,我有一个文件如下 0033613766442 007969947485 01027709100 0113204909 01132049819 01132100218 01132127941 01132179212 我想要一个命令只显示包含11个字符的行?您可以说: grep -P '^.{11}$' filename 这将打印包含11个字符的行。使用awk可以这样做 awk 'length($0)==11' file 01027709100 01132049819 01132100218 0

我有一个文件如下

0033613766442
007969947485
01027709100
0113204909
01132049819
01132100218
01132127941
01132179212
我想要一个命令只显示包含11个字符的行?

您可以说:

grep -P '^.{11}$' filename

这将打印包含11个字符的行。

使用
awk
可以这样做

awk 'length($0)==11' file
01027709100
01132049819
01132100218
01132127941
01132179212

还是这个短的变异

awk 'NF==11' FS= file

到目前为止你有什么代码?请发布。
length
无参数默认长度为
$0
,因此
length==11
将生效。