searching regular expressions with special characters like dot using grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting searching regular expressions with special characters like dot using grep
# 1  
Old 08-12-2009
searching regular expressions with special characters like dot using grep

hi everybody

I am a new user to this forum and its previous posts have been very useful. I'm searching in a file using grep for patterns like

12.13.444
55.44.443

i.e. of form
<digit><digit>.<digit><digit>.<digit><digit><digit>

Can anybody help me with this.

Thanks in advance
# 2  
Old 08-12-2009
Code:
grep -e '^[0-9][0-9]\.[0-9][0-9]\.[0-9][0-9][0-9]$'

Or, if you have a better version of grep than I have:
Code:
grep '^([0-9]{2}\.){2}[0-9]{3}$'

# 3  
Old 08-12-2009
hi
actually the pattern is in middle of the line and not at the beginning or at end.
so i tried the following options:

1. grep -e '[0-9][0-9]\.[0-9][0-9]\.[0-9][0-9][0-9]' file1

o/p : also gave lines with patterns as 1116.20.233

2. grep '([0-9]{2}\.){2}[0-9]{3}' file1

o/p : no output

format of file1 is

HPOvBbc=06.20.050
HPOvConf=06.20.050
HPOvCtrl=06.20.052
HPOvDepl=06.20.051
HPOvSecCC=06.20.050
HPOvSecCo=06.20.050
HPOvPCO=11510.50.180
HPOvPacc=11610.50.180
HPOvEaAgt=11708.60.005
HPOvEaAes=11808.60.005
HPOvEaAja=01198.60.005
# 4  
Old 08-12-2009
Yeah, when you took off the ^ it would have opened up the regexp too much.
Leave the $ on the end and replace the ^ at the start with \=

Should sort it.
# 5  
Old 08-12-2009
thanks for help

it is sorted
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl regular expression to remove the special characters

I had a string in perl script as below. Tue Augáá7 03:54:12 2012 Now I need to replace the special character with space. After removing the special chaacters Tue Aug 7 03:54:12 2012 Could anyone please help me here for writing the regular expression? Thanks in advance.. Regards, GS (1 Reply)
Discussion started by: giridhar276
1 Replies

2. UNIX for Dummies Questions & Answers

grep and regular expressions

Hi All, For the past many days I have solved a lot of grep and regular expression questions, Now I am in a search for a good quality set of questions that can help me build and check my knowledge of grep with regular expressions, it would be great if anyone could help me with my requirement. ... (1 Reply)
Discussion started by: rahulkalra9
1 Replies

3. Homework & Coursework Questions

Regular Expressions with GREP

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Given a text file (big_english.txt) containing roughly 250,000 words, answer the following using grep and... (2 Replies)
Discussion started by: blahblahblah123
2 Replies

4. UNIX for Dummies Questions & Answers

extract columns using grep or regular expressions

I am trying to print columns from a table whose name (header) matches a certain string. E.g., patient1001 patient1002 patient2005 patient3005 patient4001 0 0 0 0 0 2 9 2 8 3 2 7 3 0 2 Say I want to print columns whose names end with "01" patient1001 patient4001 0 0 2 3 2 2 ... (3 Replies)
Discussion started by: quextil
3 Replies

5. Shell Programming and Scripting

Searching backwards using regular expressions

I'm having trouble writing a regular expression that matches the text I need it to. Let me give an example to express my trouble. Suppose I have the following text: if(condition) multiline statement else if(condition) multiline statement else if(condition) multiline statement else... (3 Replies)
Discussion started by: Altay_H
3 Replies

6. Shell Programming and Scripting

How to grep using a line break in regular expressions?

Hi, I have a file as below, {#### if file then file else file } print file i need to fine the count of all the pattern - file, inside the { } i'm using a grep command as grep -c \{'*file*'\} fake.sh\ It doesn't gives me any result, i think the problem here is the... (5 Replies)
Discussion started by: divak
5 Replies

7. Linux

how to grep special character regular expression?

Hi :) I have 2 files file1: SNP_A-2208459 SNP_A-4215188 SNP_A-2012248 SNP_A-1882998 file2: CHR SNP UNADJ BONF HOLM * * * etc. 19 SNP_A-2236481 1.742e-26 5.442e-21 13 SNP_A-4204405 8.643e-07 1.505e-06 3 SNP_A-1860908... (11 Replies)
Discussion started by: sogi
11 Replies

8. UNIX Desktop Questions & Answers

grep with special characters

Hi there I need to grep for a detail from a file. The pattern to search for involves escape sequences in it. This causes for the problem. grep "P\_SOME\_STRING\_SEARCH" filename Note, I have line like below in the file and expect it to grep. select * from my_system_param ... (3 Replies)
Discussion started by: guruparan18
3 Replies

9. UNIX for Dummies Questions & Answers

grep and regular expressions :

I wrote a simple korn shell where I am trying to filter all the good record layouts of a file to only leave the bad ones to look at. That file is hudge. Aside from '# comments' and 'var=ssss', all record should follow a specific record layout, with comma seperated fields. Some fields can have any... (2 Replies)
Discussion started by: Browser_ice
2 Replies

10. UNIX for Dummies Questions & Answers

More Grep - Regular Expressions

Hey all! I'm trying to search a file and return all instances of a word, let's say 'foo' in this case, as long as it's not a function name. For example: 1) int foo; //OK 2) //'this is totally fooed up' is also OK 3) int foo (int x, int y) //not ok to return I've tried a lot of regular... (7 Replies)
Discussion started by: Jombee
7 Replies
Login or Register to Ask a Question