'grep -n ' \.*' test.txt' 和 grep -n '\.*' test.txt 之间有什么区别

'grep -n ' \.*' test.txt' 和 grep -n '\.*' test.txt 之间有什么区别

当我运行时grep -n ' \.*' test.txt,我得到:

1:Hello! This is a Unix \ Linux test text file.
2:It is being used to check multiple grep commands.
3:It is very useful.
4:.Below are some tabular information.

但是,当我运行时grep -n '\.*' test.txt,我得到:

1:Hello! This is a Unix \ Linux test text file.
2:It is being used to check multiple grep commands.
3:It is very useful.
4:.Below are some tabular information.
5:
6:101|Raj|Surat|10000
7:102|Devi|Surat|50000
8:103|Faris|Mumbai|12500
9:104|Rashmi|Puna|20000
10:105|Raj|Kolkata|60000
11:106|Taher|Mumbai|90000
12:
13:1
14:2
15:4
16:554
17:3532
18:75
19:
20:^^^^veikalvktpjktpogksl;cdfhrtywsdgui;jmdrs
21:gykiuotdawwrf
22:hkitdsegm,oiuhgdwdb$$$$$

这两个命令之间的唯一区别是它们前面有一个空格,\但它们给出的输出不同。有人能解释一下区别吗?

仅供参考,我的test.txt文件如下所示:

Hello! This is a Unix \ Linux test text file.
It is being used to check multiple grep commands.
It is very useful.
.Below are some tabular information.

101|Raj|Surat|10000
102|Devi|Surat|50000
103|Faris|Mumbai|12500
104|Rashmi|Puna|20000
105|Raj|Kolkata|60000
106|Taher|Mumbai|90000

1
2
4
554
3532
75

^^^^veikalvktpjktpogksl;cdfhrtywsdgui;jmdrs
gykiuotdawwrf
hkitdsegm,oiuhgdwdb$$$$$

答案1

Grep 使用正则表达式 (regex) 搜索文本。它逐行读取文件。

一个命令是匹配“0到无穷次之间的一个单点.”,也就是'\.*'

另一个是寻找“一个空格,后跟一个点 . 介于 0 到无穷次之间”,也就是' \.*'

虽然基本上任何行都包含“0 到无穷大点”(好吧,它不能是其他任何东西),但只有少数行包含空格。

相关内容