LinuxQuestions.org
Help answer threads with 0 replies.
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 04-05-2005, 03:42 PM   #1
UrbanDruid
LQ Newbie
 
Registered: Apr 2005
Posts: 4

Rep: Reputation: 0
Extracting text with grep or awk?


Hey, kids!

I have a couple of text file reports in a format like this:

8/25/2004 8:23:30 AM 0x1000000 0x1 5,059 E:\Project 68950\Project 68950 2-up cover report
8/25/2004 8:23:32 AM 0x1000000 0x1 675,328 E:\Project 68950\Project 68950 2-up covers
7/13/1990 1:00:14 PM 0x1000000 0x1 0 E:\Project 68950\Fonts\Helve
8/5/1993 5:02:32 AM 0x1000000 0x1 0 E:\Project 68950\Fonts\HelveNeuMedCon
8/25/2004 8:19:02 AM 0x1000000 0x1 0 E:\Project 68950\Fonts\Helvetica
8/13/2004 10:49:30 AM 0x1000000 0x1 0 E:\Project 68950\Fonts\Helvetica Neue Condensed 3


All I need out of it are the "Project 68950" sections, and preferably only unique occurrences.

Columns are separated by varying numbers of spaces, rather than tabs, but the text I need will always appear between the first pair of backslashes in each line. Because of this I thought grep might be the way to go, but can't figure out how to do it. And unfortunately I know more about full-contact knitting than I do about awk.

Any advice? (For added marks: in the other file the text I need is between the second and third backslashes.)

Cheers!

--Gord
 
Old 04-05-2005, 03:53 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
In awk ...
Code:
awk '{for(i=7;i<=NF;i++)printf $i" ";print""}' <report_name> | uniq
Or, a bit more elegant, using sed :)
Code:
sed 's/.*\(E:\)/\1/g' <report_name>|uniq

Cheers,
Tink

Last edited by Tinkster; 04-05-2005 at 04:12 PM.
 
Old 04-07-2005, 12:01 PM   #3
UrbanDruid
LQ Newbie
 
Registered: Apr 2005
Posts: 4

Original Poster
Rep: Reputation: 0
Tink!

Many thanks. Unfortunately, those give me the whole path (e.g., "E:\Project 68950\Project 68950 2-up cover report") for each file/directory in "Project 68950," when all I want is unique occurrences of "Project 68950."

These reports are the contents of backup tapes and all I need to know is which projects are on them, not every file.

I dug around in the man pages of awk and sed to figure out your examples and I think I burst a blood vessel. If you can take another crack I'd appreciate it.

Cheers!

--Gord
 
Old 04-07-2005, 01:53 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Oh ... I got you wrong the first time round, that makes it
even easier ;) ... when you referred to it as section I
assumed you wanted the font names.

awk -F\\ '{print $2}' <report_name> | uniq


Cheers,
Tink
 
Old 04-07-2005, 02:08 PM   #5
UrbanDruid
LQ Newbie
 
Registered: Apr 2005
Posts: 4

Original Poster
Rep: Reputation: 0
Perfect! Grazie!
 
Old 04-07-2005, 02:57 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Quote:
Originally posted by UrbanDruid
Perfect! Grazie!
Prego ;)


Cheers,
Tink
 
  


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
Bash script question (grep and awk) hamish Linux - Software 6 04-06-2005 03:14 PM
grep problem in extracting special characters imppayel Programming 8 12-02-2004 07:28 AM
Can I use grep inside awk? Helene Programming 6 04-27-2004 12:58 AM
Newbie playing with Awk and Grep Helene Programming 6 04-15-2004 02:08 AM
newbie needs help for grep and awk parker Programming 1 08-12-2003 04:24 AM


All times are GMT -5. The time now is 02:52 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration