PDA

View Full Version : Grep command



achuth
January 15th, 2012, 07:23 AM
Sir,
Consider the following file content

This line contains the number 113. # Match.
This line contains the number 13. # No match.
This line contains the number 133. # No match.
This line contains the number 1133. # Match.
This line contains the number 113312. # Match.
This line contains the number 1112. # No match.
This line contains the number 113312312. # Match.
This line contains no numbers at all. # No match.


Now consider the following command:
$ grep "1133*" filename

The output is
This line contains the number 113. # Match.
This line contains the number 1133. # Match.
This line contains the number 113312. # Match.
This line contains the number 113312312. # Match.

I don't understand why the first line is displayed eventhough there is no "1133".
Why is it so?

adityamagadi
January 15th, 2012, 07:27 AM
it is because you are using * in your grep command

Bachstelze
January 15th, 2012, 07:28 AM
1133* means 113 followed by any number of occurrences of 3, including zero.

man 7 regex

achuth
January 17th, 2012, 02:14 AM
Is this the same for UNIX OS?

Arndt
January 17th, 2012, 09:48 AM
Is this the same for UNIX OS?

The same as what?

Idyll
January 17th, 2012, 10:02 AM
Yes, it works the same way in UNIX System V and Solaris 2.0. I just verified in my "UNIX in a Nustshell" book.

The symbol * "matches zero or more preceding" pattern or character specified.