Welcome to the Linux Foundation Forum!

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

Comments

  • gomer
    gomer Posts: 158
    * == 0 or more times == always matches .*

    try + instead of *

Categories

Upcoming Training