View previous topic :: View next topic |
Author |
Message |
klieber Bodhisattva
Joined: 17 Apr 2002 Posts: 3657 Location: San Francisco, CA
|
Posted: Thu May 30, 2002 6:44 pm Post subject: one for the sed gurus out there. |
|
|
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 |
|
|
fghellar Bodhisattva
Joined: 10 Apr 2002 Posts: 856 Location: Porto Alegre, BR
|
Posted: Thu May 30, 2002 8:28 pm Post subject: |
|
|
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 |
|
|
klieber Bodhisattva
Joined: 17 Apr 2002 Posts: 3657 Location: San Francisco, CA
|
Posted: Thu May 30, 2002 9:12 pm Post subject: |
|
|
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 |
|
|
handsomepete Guru
Joined: 21 Apr 2002 Posts: 548 Location: Kansas City, MO
|
Posted: Thu May 30, 2002 11:18 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
klieber Bodhisattva
Joined: 17 Apr 2002 Posts: 3657 Location: San Francisco, CA
|
Posted: Thu May 30, 2002 11:27 pm Post subject: |
|
|
handsomepete wrote: | Would do the same thing. |
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 |
|
|
handsomepete Guru
Joined: 21 Apr 2002 Posts: 548 Location: Kansas City, MO
|
Posted: Thu May 30, 2002 11:52 pm Post subject: |
|
|
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 |
|
|
klieber Bodhisattva
Joined: 17 Apr 2002 Posts: 3657 Location: San Francisco, CA
|
Posted: Fri May 31, 2002 12:01 am Post subject: |
|
|
handsomepete wrote: | I understand that everyone has their preferences. |
One of my favorite unix-isms:
Quote: | Top 2 Rules of *nix administration:- There is always more than one way to do something.
- 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 |
|
|
craftyc Guru
Joined: 23 May 2002 Posts: 443 Location: Behind You.
|
Posted: Fri May 31, 2002 1:49 pm Post subject: |
|
|
klieber wrote: | handsomepete wrote: | I understand that everyone has their preferences. |
One of my favorite unix-isms:
Quote: | Top 2 Rules of *nix administration:- There is always more than one way to do something.
- 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 |
|
|
|