Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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