1

When I run grep -n ' \.*' test.txt , I get:

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.

However, when I run grep -n '\.*' test.txt, I get:

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$$$$$

The only difference between both the commands is they have a space before the \ but they give different outputs. Can someone explain the difference?

Just for ref, this is what my test.txt file looks like:

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$$$$$
0

1 Answer 1

2

Grep uses regular expressions (regex) for searching for text. It reads a file line by line.

One command is matching "one single dot . between 0 to infinity times", that would be '\.*'.

The other one is looking for "one single space, followed by a dot . between 0 to infinity times", which would be ' \.*'.

While basically any line contains "0 to infinity dots" (well, it can't be anything else), only a few lines contain a space.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .