Welcome to the new 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

[[email protected] ~]# more example.txt

Lin

Line

Linux

Linuz

Linus

[[email protected] ~]#

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

[[email protected] ~]# sed '/Lin*/p' example.txt

Lin

Lin

Line

Line

Linux

Linux

Linuz

Linuz

Linus

Linus

[[email protected] ~]# sed '/Lin.*/p' example.txt

Lin

Lin

Line

Line

Linux

Linux

Linuz

Linuz

Linus

Linus

[[email protected] ~]#

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

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

    try + instead of *
Sign In or Register to comment.