Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-14-2010
Registered User
 

Join Date: Feb 2010
Location: USA
Posts: 65
Thanks: 1
Thanked 0 Times in 0 Posts
grep searching

I am making a script but having little problem. at one part I need to find one number format or other format from a file..
those formats are xxx-xx-xxxx or xxxxxxxxx
i tried

Code:
grep '( [0-9]\{3\}-[0-9]\{2\}-[0-9]\{3\} |[0-9]\{9\})'

if i do them sepratly it work but like this it is not working
Please check what the problem is with this code

Thanks
Sponsored Links
    #2  
Old 03-14-2010
Registered User
 

Join Date: Sep 2008
Location: In the beautiful World...
Posts: 509
Thanks: 9
Thanked 27 Times in 27 Posts
How about this...

Code:
grep  -E '[0-9]{3}-[0-9]{2}-[0-9]{3}|[0-9]{9}'

-E(or just use egrep) which is for extended regular expression, read the man page for grep
Sponsored Links
    #3  
Old 03-14-2010
Registered User
 

Join Date: Feb 2010
Location: USA
Posts: 65
Thanks: 1
Thanked 0 Times in 0 Posts
i tried but it's not working. when i use egrep or grep -E it does not return anything.
The problem is like this.

Code:
some command | some command | some command | grep -E  '( [0-9]\{3\}-[0-9]\{2\}-[0-9]\{3\} |[0-9]\{9\})'

This does not return anything

but if i do separately then both works

Code:
some command | some command | some command | grep  '( [0-9]\{3\}-[0-9]\{2\}-[0-9]\{3\} '


Code:
some command | some command | some command | grep [0-9]\{9\})'

    #4  
Old 03-14-2010
rdcwayx rdcwayx is offline Forum Advisor  
Use nawk in Solaris
 

Join Date: Jun 2006
Posts: 2,632
Thanks: 43
Thanked 383 Times in 373 Posts
Your system's grep doesn't support -E, please replace by egrep.


Code:
some command | some command | some command | egrep  '( [0-9]\{3\}-[0-9]\{2\}-[0-9]\{3\} |[0-9]\{9\})'

Sponsored Links
    #5  
Old 03-15-2010
Registered User
 

Join Date: Feb 2010
Location: USA
Posts: 65
Thanks: 1
Thanked 0 Times in 0 Posts
it is not working either. can you check if the grouping is right or not. or is there any other comand which i can use to take out 2 particular format of number from a file
Sponsored Links
    #6  
Old 03-15-2010
rdcwayx rdcwayx is offline Forum Advisor  
Use nawk in Solaris
 

Join Date: Jun 2006
Posts: 2,632
Thanks: 43
Thanked 383 Times in 373 Posts
Do you try malcomex999's command? (They are different with yours.)


Code:
grep  -E '[0-9]{3}-[0-9]{2}-[0-9]{3}|[0-9]{9}'

egrep '[0-9]{3}-[0-9]{2}-[0-9]{3}|[0-9]{9}'

Sponsored Links
    #7  
Old 03-15-2010
Registered User
 

Join Date: Feb 2010
Location: USA
Posts: 65
Thanks: 1
Thanked 0 Times in 0 Posts
Thank you for figuring that out...the problem was, I was using same [0-9]\{3\} but the way he use [0-9] {3} works fine.. thanks

Last edited by Learnerabc; 03-15-2010 at 12:12 AM.. Reason: misprint
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
searching fileextentions (suffix) with grep and/or test arjanengbers Shell Programming and Scripting 4 03-04-2010 04:56 AM
searching regular expressions with special characters like dot using grep jpriyank Shell Programming and Scripting 4 08-12-2009 03:04 AM
searching using grep command prakash.gr Shell Programming and Scripting 9 12-15-2008 03:30 AM
GREP Searching for a newbie... steveglevin Shell Programming and Scripting 8 08-27-2007 03:10 AM
grep - searching for a specific string manthasirisha Shell Programming and Scripting 2 01-05-2006 08:24 AM



All times are GMT -4. The time now is 03:48 AM.