Egrep, starting with r and ending with g

I need to find and display the lines in the shell using egrep that start with r and end with g.

I have

egrep -e "^r*g$" testfile.txt 

but it does not give me any results, what am I doing wrong?

+7
source share
2 answers

Appendix a . should work

 egrep -e "^r.*g$" 

This basically means: everything that starts with r, then is followed by zero or more than anything, and then ends with the letter g.

checked for

 r fsgdfs gfsdg fooo bar rfoo g fdsqfdsq rg 

he returns

 r fsgdfs gfsdg rfoo g rg 
+10
source

* matches r , not "nothing in between." Update it to .* And you will see the results:

 egrep -e "^r.*g$" testfile.txt 
0
source

All Articles