Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

egrep question 1

Status
Not open for further replies.

TheDash

MIS
Mar 25, 2004
171
US
Hi,

I am trying to grep two words that end with ZZZ. They begin with AAA or BBB. Can somebody help with this?

This won't work.

egrep '^[AAA][ZZZ]$|^[BBB][ZZZ]$'
 
egrep '^(AAA|BBB).*ZZZ$' file

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
.*

. - any character
* - preceeding character repeated 0 or more times

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi..

I used it here ..

ls -l dirname | egrep '^(AAA|BBB).*ZZZ$'

to check for file names ... why doesn't it work?
 
'couse....
"^" - stands for the BEGINNING of the line.

What's the beginning of the line of 'ls -l'?

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
ok, thanks

ls -l dirname | egrep '.*(AAA|BBB).*ZZZ$' solved it.
 
what about file: fooAAAbarZZZ.txt ?

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I meant to say:
fooAAAbarZZZ

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
hint:
ls -l | egrep '.*[ ]+(AAA|BBB)[^ ]+ZZZ$'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top