Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Picking package names from emerge output
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
tmo
n00b
n00b


Joined: 16 Jun 2003
Posts: 25
Location: Finland

PostPosted: Sun Dec 18, 2005 12:48 pm    Post subject: Picking package names from emerge output Reply with quote

Tired of manually picking package names from emerge output?

emerge-cut-pkg:
Code:

#!/bin/sh
sed -n 's/^[^]]*U \] \+\([^ ]*\).*/=\1/p'


Usage:
Code:

# save list of packages to a tmp file because emerge is dog-slow
$ emerge -puD world | emerge-cut-pkg > /tmp/out

$ cat /tmp/out
=sys-kernel/linux-headers-2.6.11-r3
=sys-libs/glibc-2.3.5-r3
=x11-libs/xtrans-1.0.0
=x11-libs/libICE-1.0.0
...

# emerge (pretend) only x11-libs/*
$ emerge -pvt `grep x11-libs /tmp/out`

These are the packages that I would merge, in reverse order:

Calculating dependencies ...done!
[ebuild     U ] x11-libs/libXevie-1.0.0 [0.99.3] 201 kB
[ebuild     U ] x11-libs/libXinerama-1.0.0 [0.99.2] 196 kB
[ebuild     U ] x11-libs/libXrandr-1.1.0.2 [1.1.0.1] 206 kB
...


Edited the sed expression to include only updated packages


Last edited by tmo on Mon Dec 19, 2005 1:59 pm; edited 1 time in total
Back to top
View user's profile Send private message
roseZ
n00b
n00b


Joined: 17 Dec 2005
Posts: 31
Location: Finland

PostPosted: Mon Dec 19, 2005 9:12 am    Post subject: Reply with quote

Nice idea! I Wonder why I didn't come up with this myself. Maybe I'm still not lazy enough :D

One question, though: what's the purpose of \+ in the expression? Works without it, too.
I suppose it doesn't match a literal + and I couldn't find an explanation with a few searches
So please, educate me.
Back to top
View user's profile Send private message
roseZ
n00b
n00b


Joined: 17 Dec 2005
Posts: 31
Location: Finland

PostPosted: Mon Dec 19, 2005 11:18 am    Post subject: Reply with quote

Silly me. It seems to work like I tought + would do alone (match one or more occurrences
of the previous block). I just don't understand why it has to be escaped. Back in the days,
at least Rute used to teach this the other way around.
Back to top
View user's profile Send private message
tmo
n00b
n00b


Joined: 16 Jun 2003
Posts: 25
Location: Finland

PostPosted: Mon Dec 19, 2005 12:22 pm    Post subject: Reply with quote

roseZ wrote:
Silly me. It seems to work like I tought + would do alone (match one or more occurrences
of the previous block). I just don't understand why it has to be escaped. Back in the days,
at least Rute used to teach this the other way around.


Maybe sed got support for '+' later and without escaping it would have broken backward compatibility, I don't know really :)

I wonder why emerge doesn't have an option to output package names only...
Back to top
View user's profile Send private message
roseZ
n00b
n00b


Joined: 17 Dec 2005
Posts: 31
Location: Finland

PostPosted: Mon Dec 19, 2005 9:26 pm    Post subject: Reply with quote

Ok, I did what I should have done right from the start. Read the man page of sed (and grep), that is :)

Apparently there are two kinds of regexps: basic and extended. Default for sed and grep is the former,
in which characters like ? + ( | { lose their special meaning unless preceded by a backslash.
I think I like the extended mode better, since it's more consistent. Excaping invokes literal meaning
instead of the opposite for all characters.

So we could shave a few characters off the script:
Code:

#!/bin/sh
sed -nr 's/^[^]]*U \] +([^ ]*).*/=\1/p'

This will undoubtedly sacrifice some portability, although \+ is already a GNU extension ;)

About portage tools, they could definitely be polished, but the devs must have their hands full.
Back to top
View user's profile Send private message
slycordinator
Advocate
Advocate


Joined: 31 Jan 2004
Posts: 3059
Location: Korea

PostPosted: Fri Oct 13, 2006 1:10 am    Post subject: Reply with quote

I like this better:

Code:
#!/bin/sh
sed -n 's/^[^]]*\] \+\([^ ]*\).*/=\1/p'


This gets all packages. I had edited the script before and couldn't figure out why it was missing every package that portage wanted to downgrade. Didn't take long to figure it out.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks 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