A message for Linux.com registered users: We are in the process of making changes to the Linux forums. Starting Monday, 8/13/18 at 6:00 PM PT, you will be unable to access the forums. They will re-launch as soon as possible on Wednesday, 8/15/18 with new features and improved functionality. Thank you for your patience and stay tuned for the new improved forums.

March 9, 2010

sed script

Hi

I am learning regular expressions. I have a doubht for the bellow patterns. Can anyone please explain this.

1.I created a test file example.txt
[root@localhost ~]# more example.txt
Lin
Line
Linux
Linuz
Linus
[root@localhost ~]#

2.I ran sed command with two dofferent patterns, but it is giving the same output for both the patterens.

[root@localhost ~]# sed '/Lin*/p' example.txt
Lin
Lin
Line
Line
Linux
Linux
Linuz
Linuz
Linus
Linus
[root@localhost ~]# sed '/Lin.*/p' example.txt
Lin
Lin
Line
Line
Linux
Linux
Linuz
Linuz
Linus
Linus
[root@localhost ~]#

If the dot(.) matches any character then the patteren Lin.* should not match Lin, but here it is displaying the same output for both the patterens Lin.* and Lin*

Thanks in advamce.

Regards

Click Here!