Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-02-2005, 06:47 AM   #1
LQ Newbie
Registered: Apr 2005
Posts: 26

Rep: Reputation: 16
Help with egrep

I have a formatted file a portion of which I have given below:

2005-05-01/23:00:23 STICKER 23452010-ABE3098 Line one asdkjad a
2005-05-01/23:01:10 STICKER 23452010-ABE3098 I want this jha
2005-05-01/23:02:03 STICKER 23452010-ABE3098 klja fjskl s
2005-05-01/23:02:05 STICKER 23452010-ABE3098 hksf s f

Using egrep, I want to match the second line in the above set. Problem is, there are a set of similar lines in the file, and for each of these lines, all I know is the first field 2005-05-01/23:01:10, and the last one [partiall] : I want. The second and third column remain same length wise and in format. Is there some way I can use egrep to get the required lines?

I tried, egrep "2005-05-01/23:01:10 [A-Z]{7} [A-F0-9-]{16} I want" <filename>.

However, I got no match for this. Any suggestions?
Old 05-02-2005, 08:13 AM   #2
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977
well you've not really specified what makes it the line that your want.. if you're saying it's the one with a known phase at the end, then it should be simple:

grep -e "I want" filename

if it's starting with a fixed date string (why would that ever happen??) then

grep -e "^2005-05-01/23:01:10.*+I want" filename
Old 05-02-2005, 08:18 AM   #3
LQ Newbie
Registered: Apr 2005
Posts: 26

Original Poster
Rep: Reputation: 16
Well, since it is a log file, it has a date field.

Coming back to the query, I tried out what you gave, and it works like a dream! Thanks a tonne. But can you explain the use of * and +? I had earlier tried .*? and it failed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing out html with egrep binaryechoes Linux - Newbie 3 12-02-2005 12:41 AM
egrep multiple files smart_sagittari Linux - Newbie 2 06-27-2005 08:57 AM
egrep question internal_war Linux - Newbie 6 05-05-2005 06:32 PM
Using Grep and Egrep linux-nerd Linux - General 5 10-10-2004 11:37 AM
Using egrep Barbarian Programming 5 10-20-2002 02:54 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:33 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration