Solved

regex pattern help - can't get a grep "regex" file to work.

Posted on 2006-11-08
2
314 Views
Last Modified: 2010-04-21
I am trying to make retrieve a regex pattern. I would like to retrieve a pattern of 1-3 digits followed by a colon followed by the same again.

For example:
$ cat test.txt
1:2:
13:26:
3:26:
333:26:
36:6:
333:263:

I would like to have all these patterns printed.
Here is what I get:
$ grep -e '\d{1,3}:d{1,3}:' test.txt
~/tmp $  

Nothing.

I will also have to be printing the same pattern with a space before and after in another file.  I have been using:
grep -e '\s\d{1,3}:d{1,3}:\s' test.txt
without success.

Any help appreciated.

Thanks,
ibanja

0
Comment
Question by:ibanja
2 Comments
 
LVL 58

Accepted Solution

by:
amit_g earned 250 total points
ID: 17899717
egrep '[0-9]{1,3}:[0-9]{1,3}' test.txt
0
 

Author Comment

by:ibanja
ID: 17901124
That certainly does it.

I noticed a typo in my question.  I had:
grep -e '\d{1,3}:d{1,3}:' test.txt
but I'd been using:
grep -e '\d{1,3}:\d{1,3}:' test.txt    

No matter.  It didn't work.

Thanks amit_g
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now