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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
04-05-2005, 03:42 PM
|
#1
|
|
LQ Newbie
Registered: Apr 2005
Posts: 4
Rep:
|
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
|
|
|
|
04-05-2005, 03:53 PM
|
#2
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,916
|
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.
|
|
|
|
04-07-2005, 12:01 PM
|
#3
|
|
LQ Newbie
Registered: Apr 2005
Posts: 4
Original Poster
Rep:
|
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
|
|
|
|
04-07-2005, 01:53 PM
|
#4
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,916
|
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
|
|
|
|
04-07-2005, 02:08 PM
|
#5
|
|
LQ Newbie
Registered: Apr 2005
Posts: 4
Original Poster
Rep:
|
Perfect! Grazie!
|
|
|
|
04-07-2005, 02:57 PM
|
#6
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,916
|
Quote:
Originally posted by UrbanDruid
Perfect! Grazie!
|
Prego ;)
Cheers,
Tink
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:52 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|