Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
one for the sed gurus out there.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
klieber
Bodhisattva
Bodhisattva


Joined: 17 Apr 2002
Posts: 3657
Location: San Francisco, CA

PostPosted: Thu May 30, 2002 6:44 pm    Post subject: one for the sed gurus out there. Reply with quote

Can one of you sed experts out there come up with a command that will turn this:

Code:
[ebuild  N   ] sys-devel/libtool-1.4.1-r7 to /
[ebuild  N   ] sys-devel/m4-1.4p to /
[ebuild  N   ] sys-apps/groff-1.17.2-r1 to /


into this:

Code:
libtool-1.4.1-r7
m4-1.4p
groff-1.17.2-r1


Basically, I want to be able to feed sed a text file built from an emerge -p command and have sed filter out only the package name. (I'm also not married to sed -- perl/whatever would be fine as well.)

This is for a tip that I'm working on for the tips and tricks forum. If you can help me out, I'll make sure your name is emblazoned in all the glory that the Tips & Tricks forum can offer. :)

--kurt
_________________
The problem with political jokes is that they get elected
Back to top
View user's profile Send private message
fghellar
Bodhisattva
Bodhisattva


Joined: 10 Apr 2002
Posts: 856
Location: Porto Alegre, BR

PostPosted: Thu May 30, 2002 8:28 pm    Post subject: Reply with quote

In the Articles section of the Gentoo web site, there is a series of three articles by Daniel Robbins about awk, called Awk by example (number 5 in that list). Those can most surely get you where you want to go... :)
_________________
| www.gentoo.org | www.tldp.org | www.google.com |
Back to top
View user's profile Send private message
klieber
Bodhisattva
Bodhisattva


Joined: 17 Apr 2002
Posts: 3657
Location: San Francisco, CA

PostPosted: Thu May 30, 2002 9:12 pm    Post subject: Reply with quote

Figured it out:

Code:
sed -e 's/^[^\/]*\/\([^ ]*\).*$/\1/g' mylist.txt


(fghellar -- thanks for those article pointers -- there were some sed ones right below the awk ones. Got me started.)

If anyone can make that sed command cleaner, please let me know. I'm no sed expert, so my feelings won't be hurt. :)

--kurt
_________________
The problem with political jokes is that they get elected
Back to top
View user's profile Send private message
handsomepete
Guru
Guru


Joined: 21 Apr 2002
Posts: 548
Location: Kansas City, MO

PostPosted: Thu May 30, 2002 11:18 pm    Post subject: Reply with quote

Sorry, couldn't resist. Not trying to stuff awk down your throat, but...

Code:
awk -F' ' '{print $4}' mylist.txt


Would do the same thing. :D
Back to top
View user's profile Send private message
klieber
Bodhisattva
Bodhisattva


Joined: 17 Apr 2002
Posts: 3657
Location: San Francisco, CA

PostPosted: Thu May 30, 2002 11:27 pm    Post subject: Reply with quote

handsomepete wrote:
Would do the same thing. :D


Almost the same thing -- at least on my system, this is what it spits out:

Code:
sys-devel/libtool-1.4.1-r7
sys-devel/m4-1.4p
sys-apps/groff-1.17.2-r1


Which isn't quite what I need.

That said, I'm sure it can be done in awk -- I'm just more familiar with the vi-like search/replace functionality of sed. (or the sed-like search/replace functionality of vi. ;))

--kurt
_________________
The problem with political jokes is that they get elected
Back to top
View user's profile Send private message
handsomepete
Guru
Guru


Joined: 21 Apr 2002
Posts: 548
Location: Kansas City, MO

PostPosted: Thu May 30, 2002 11:52 pm    Post subject: Reply with quote

Whoops, missed that slash. I'll leave it alone. I understand that everyone has their preferences (I imagine some people think we're freaks for prefering gentoo over other distros... :) )

Ok, I can't leave it alone. Sorry. For the record:
awk -F/ '{print $2}' myfile.txt | awk -F' ' '{print $1}'

I'll stop now. I promise.
Back to top
View user's profile Send private message
klieber
Bodhisattva
Bodhisattva


Joined: 17 Apr 2002
Posts: 3657
Location: San Francisco, CA

PostPosted: Fri May 31, 2002 12:01 am    Post subject: Reply with quote

handsomepete wrote:
I understand that everyone has their preferences.


One of my favorite unix-isms:

Quote:
Top 2 Rules of *nix administration:
  1. There is always more than one way to do something.
  2. Someone thinks that your way is wrong.


I can't remember where I first saw that, but it's always stuck with me, both because it's so funny as well as so true. :)

--kurt
_________________
The problem with political jokes is that they get elected
Back to top
View user's profile Send private message
craftyc
Guru
Guru


Joined: 23 May 2002
Posts: 443
Location: Behind You.

PostPosted: Fri May 31, 2002 1:49 pm    Post subject: Reply with quote

klieber wrote:
handsomepete wrote:
I understand that everyone has their preferences.


One of my favorite unix-isms:

Quote:
Top 2 Rules of *nix administration:
  1. There is always more than one way to do something.
  2. Someone thinks that your way is wrong.


I can't remember where I first saw that, but it's always stuck with me, both because it's so funny as well as so true. :)

--kurt


Damn right :)
_________________
Postcount ++
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum