LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-09-2008, 08:59 PM   #1
chibi2666
LQ Newbie
 
Registered: Nov 2008
Posts: 19

Rep: Reputation: 0
Regular Expression help


Hi guys,


I need help with this problem,


I am trying to write a regular expression that will match the following line's City, ST 12345


I tried grep -i -E "([a-z][a-z]|1-5)" iwashere is the file name


Does this look correct or could you show me another way to write this. Any help would be great. Thank you
 
Old 11-09-2008, 09:47 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,823
Blog Entries: 1

Rep: Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218
Code:
cat iwashere | sed -n '/[A-Za-z],[ ]ST[ ][0-9]/p'
I'm not a sed expert, but it matches your line. It might not be what you want. What are other lines in the file? Are they all starting with 'City'? Do they all include 'ST'? If you tell us more about the context, it'll be easier to answer.
 
Old 11-09-2008, 10:10 PM   #3
chibi2666
LQ Newbie
 
Registered: Nov 2008
Posts: 19

Original Poster
Rep: Reputation: 0
regular expression

Quote:
Originally Posted by sycamorex View Post
Code:
cat iwashere | sed -n '/[A-Za-z],[ ]ST[ ][0-9]/p'
I'm not a sed expert, but it matches your line. It might not be what you want. What are other lines in the file? Are they all starting with 'City'? Do they all include 'ST'? If you tell us more about the context, it'll be easier to answer.

HI,

Thanks for the reply

It would be like

Chico,CA 95928
Seattle,WA 42178
Miami,FL 12345
City can be more than one word and ST is two capital letters


Sorry I'm still new hope this helps

I think as long as it will match the following form
 
Old 11-09-2008, 10:37 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
I think you need to show an example of the total content of the file, and of what you would like the final output to look like.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expression Ammad Linux - General 5 08-01-2008 07:41 AM
regular expression [tT]h* sycamorex Programming 3 01-15-2008 04:43 PM
Anyone know regular expression? ahhua Linux - Software 1 12-04-2003 08:13 AM
Regular Expression Help WeNdeL Linux - General 1 08-14-2003 10:08 AM
Regular Expression slizadel Programming 4 07-28-2003 05:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration