Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

egrep lines starting with r and ending with g

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

I have

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

but it is not giving me any results, what am I doing wrong?

like image 245
Mack Gray Avatar asked Oct 01 '12 17:10

Mack Gray


1 Answers

adding a . should work

egrep -e "^r.*g$"

It basically means : everything that starts with a r, then is followed by zero or more anything, and then ends with g.

tested against

r fsgdfs gfsdg
fooo bar
rfoo g
fdsqfdsq

rg

it returns

r fsgdfs gfsdg
rfoo g
rg
like image 81
pjam Avatar answered Sep 18 '22 11:09

pjam