-   Linux - General (
-   -   Using grep and expressions (

LordJohn 03-28-2010 12:45 PM

Using grep and expressions
How can I use grep expressions so that i can find strings like the ones bellow:

New York, NY
Virginia, VA
Oregon, OR

As you can see each city starts with capital letter then it follows up with a comma, and then with the Abbreviation of the city.

I used :


grep -w '[A-Z].*[a-z][,][' '][A-Z][A-Z]' filename
But i get no results.. pls help meeee

clb 03-28-2010 01:41 PM

grep -w '[A-Z][a-zA-Z]*[,][ ]*[A-Z][A-Z]' <FILENAME> works for me.

I'm no regex expert so it could probably be refined a bit.

If you want to match one uppercase letter, and the rest of the city name must be lowercase:
grep -w '[A-Z].[a-z]*[,][ ]*[A-Z][A-Z]' <FILENAME> seems to work

LordJohn 03-28-2010 04:45 PM

Really thx
You are a life saver... :P

All times are GMT -5. The time now is 11:22 AM.