1
cat file.txt | grep -x "\d*"
grep: \Documents and Settings: Is a directory

我想搜索file.txt仅是数字的任何行,但 grep 似乎将其\d*视为文件的通配符而不是模式。我如何指定它是模式并且它应该使用标准输入来 grep 什么?

该文件充满了日期时间戳行,有些以字母结尾,有些则没有。

20140110122200
20131208041510M
...

我试图只得到不以字母结尾的行。

编辑:我也尝试过设置文件名而不是用 cat 管道。没有太大的不同。

C:\long\path>grep -ex "\d*" -f file.txt
grep: \Dell: Is a directory
grep: \Documents and Settings: Is a directory
4

1 回答 1

0

Why are you using cat to pass the file to grep? Why not just give grep the filename directly?

grep -x '\d*' file.txt

I think the actual problem you're seeing is that the * wildcard is being expanded. That's why grep is giving you errors that mention actual directories (beginning with 'd') on your system.

于 2014-01-10T19:27:37.227 回答