LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 05-02-2005, 07:47 AM   #1
smart_sagittari
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, 09:13 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
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, 09:18 AM   #3
smart_sagittari
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
 
  


Reply


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 01:41 AM
egrep multiple files smart_sagittari Linux - Newbie 2 06-27-2005 09:57 AM
egrep question internal_war Linux - Newbie 6 05-05-2005 07:32 PM
Using Grep and Egrep linux-nerd Linux - General 5 10-10-2004 12:37 PM
Using egrep Barbarian Programming 5 10-20-2002 03:54 PM


All times are GMT -5. The time now is 03:05 AM.

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