Solved

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

Posted on 2006-11-08
2
315 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
A "Helper" for python 2 87
Need bundled ATFTP tool for use with ESXi 4 84
specifying dependencies for an rpm 2 44
Understanding Futures with busy waiting 2 82
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

15 Experts available now in Live!

Get 1:1 Help Now