1833381 Members
3793 Online
110052 Solutions
New Discussion

Re: grep

 
SOLVED
Go to solution
Shahul
Esteemed Contributor

grep


Hi Folks

A small doubt regarding grep. I want to grep a line from a file. file goeas like this

skksjdfhglshdfgkdfmn
sdlfghsdklfgksdhfg
sdhgdfgghsdkfg
asd
skdjghkdjfg
aksjfhgkshdfgkdfd

I want to grep the last line. I know that line is starting with a, ending with d and many alphabets in between. how should I?

TIA
Shahul
7 REPLIES 7
Massimo Bianchi
Honored Contributor
Solution

Re: grep

Hi,

cat FILE | grep ^a | egrep a.*d

HTH,
Massimo



Massimo Bianchi
Honored Contributor

Re: grep

HI,

even more short:

cat TPURFILE| egrep ^a.*d$


Massimo
twang
Honored Contributor

Re: grep

To find the phase that strating with 'a' and ending with 'e':
# tail -1 |grep 'a*e'
Ernesto Cappello
Trusted Contributor

Re: grep

Hi folks


more "filename" | grep ^a |grep d$


Regards.
Ernesto.
Stefan Schulz
Honored Contributor

Re: grep

Hi,

just one more note: You don't have to use cat here. Just shorten your command to:

egrep "^a*d$" FILE

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
john korterman
Honored Contributor

Re: grep

Hi Shahul,
you could try this:

# grep "^a[a-zA-Z].[a-zA-Z]*d$"

regards,
John K.
it would be nice if you always got a second chance
H.Merijn Brand (procura
Honored Contributor

Re: grep

Ernesto's reply is completely bogus! You cannot grep the output of more, because it will be cluttered with terminal escapes. more/less/pg/$PAGER/... should *always* be the last command in a chain.

And to throw in some perl :)

# perl -ne'/^a\w*d$/ and print' file

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn