grep searching


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep searching
# 1  
Old 03-14-2010
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
# 2  
Old 03-14-2010
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
# 3  
Old 03-15-2010
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-15-2010
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\})'

# 5  
Old 03-15-2010
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
# 6  
Old 03-15-2010
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}'

# 7  
Old 03-15-2010
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 02:12 AM.. Reason: misprint
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert Text after searching via grep

Hi Team, I have a file with the following patterns: ==> xyz_Server_Started_with_Errors <== errors. ==> abc_Server_Started_with_Errors <== errors ==> reds_Server_Started_with_Errors <== errorss I want them in this format: (5 Replies)
Discussion started by: ankur328
5 Replies

2. Shell Programming and Scripting

Searching for exact match using grep

I am searching for an exact match on a value read from another file to lookup an email address in another file. The file being checked is called "contacts" and it has Act #, email address, and contact person. 1693;abc1693@yahoo.comt;Tommy D 6423;abc6423@yahoo.comt;Jim Doran... (2 Replies)
Discussion started by: ziggy6
2 Replies

3. Shell Programming and Scripting

Searching for multiple patters using grep

i have a file as below grepfile.txt ---------------- RNTO command successful No such file or directory Authentication failed if i seach individually for 'RNTO command successful' or 'No such file or directory' using grep -i as below, im gettting result. grep -i 'No such file or... (5 Replies)
Discussion started by: JSKOBS
5 Replies

4. Shell Programming and Scripting

dynamic string searching for grep

hi my code is something like count=0 echo "oracle TABLESPACE NAME nd TARGET" while do count=`expr $count + 1` (1) tts_space_name$count=`echo $tts | cut -d "," -f$count` (2) target$count=grep $(tts_space_name$count)... (2 Replies)
Discussion started by: Gl@)!aTor
2 Replies

5. Shell Programming and Scripting

Grep: Searching with a regex that contains a variable from an array

I'm attempting to grep for lines formatted like this: grep -e '^\\",' Any suggestions as to why this isn't working? ---------- Post updated at 05:03 PM ---------- Previous update was at 04:17 PM ---------- This was my solution: grep -e '^\'\",' It's hard to read, but basically I... (4 Replies)
Discussion started by: AcerAspirant
4 Replies

6. Shell Programming and Scripting

grep searching interval

Hi all, I just want to find all values that are in a specified interval. I tryed it with grep e- file , it does not work. Is it possible to get values wich are lower a special number, like grep >e-18 file? Thanks a lot (4 Replies)
Discussion started by: newcommer
4 Replies

7. Shell Programming and Scripting

searching fileextentions (suffix) with grep and/or test

Hello, I have a problem. I will search files on fileextentions (suffix). It can with the command find, but I will do it with the commands grep and/or test. When i start the script I will see all files with that extention (suffix). Can anyone help me, please? Thanks! Regards, Arjan... (4 Replies)
Discussion started by: arjanengbers
4 Replies

8. Shell Programming and Scripting

searching using grep command

Hi, i have a file called alert_pindb.log i need to grep and count for all the lines starting with "ORA-" but i need to exclude the line which is having "ORA-00600 " i am using following syntax to count the ORA- nos "grep \"ORA-\" alert_pindb.log | wc -l"; since ORA- may be anything... (9 Replies)
Discussion started by: prakash.gr
9 Replies

9. Shell Programming and Scripting

GREP Searching for a newbie...

Hi, I really need some help with GREP searching... I need to find all occurances of a file reference and remove two characters from the end of the reference. For example, here are a few lines showing the text: <image file="STRAIGHT_004CR.jpg" ALT="STRAIGHT_004CR.jpg" /> <image... (8 Replies)
Discussion started by: steveglevin
8 Replies

10. Shell Programming and Scripting

grep - searching for a specific string

ppl, this is my "file" with fields orderno orderdate orderdesc telno street city 1 01/04/2006 abc 123 100 tampa 2 01/04/2006 abc 123 100 tampa 3 01/04/2006 abc 123 100 tampa 4 01/04/2006 abc ... (2 Replies)
Discussion started by: manthasirisha
2 Replies
Login or Register to Ask a Question