Linux.com

sed script

Link to this post 09 Mar 10

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

Link to this post 09 Mar 10

* == 0 or more times == always matches .*

try + instead of *

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board