Register
It is currently Fri Oct 24, 2014 5:08 pm

Need to format and pipeline output of one command to another


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Fri Oct 08, 2010 10:10 pm   

Joined: Fri Oct 08, 2010 4:47 am
Posts: 2
Hi Everybody

This my first message in this forum :)
so # echo "Hello world!" :)

Now about issue that I I have :

I have output of command that give me list of packages that I need to compile :
Code:
# equery d mesa
[ Searching for packages depending on mesa... ]
virtual/glu-7.0 (media-libs/mesa)
virtual/opengl-7.0 (media-libs/mesa)
x11-base/xorg-server-1.7.7-r1 (!minimal? >=media-libs/mesa-7.4[nptl=])
x11-misc/fireflies-2.07 (media-libs/mesa)


I need to give this list into input of compile command , but without part inside () also without package version that always goes after '-'.
on other words I should get such line : "virtual/glu virtual/opengl x11-base/xorg-server x11-misc/fireflies"
Here what I done till now ( I will replace echo with compile command after I get to correct version of course :) )
Code:
#echo $(equery d mesa | awk '{ print $1 }'|sed 's/-//')
virtual/glu7.0 virtual/opengl7.0 x11base/xorg-server-1.7.7-r1 x11misc/fireflies-2.07


As I understand problems starts after sed gets to package "x11base/xorg-server-1.7.7-r1" that have '-' not only as version delimeter but also as part of package name.
How can I solve this ?
Also if somebody can suggest totally different way of solving this task I will be glad to see it


Top
 Profile  
 PostPosted: Tue Oct 12, 2010 10:30 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
You have to keep all the -'s before /. If you want to remove just the last -, you can use
Code:
sed -r 's%(.*/.*)-%\1%'

If you want to remove the first - after the last /, you can use
Code:
sed -r 's%(.*/[^-]*)-%\1%'

And so on. :-B


Top
 Profile  
 PostPosted: Thu Oct 14, 2010 3:32 am   

Joined: Fri Oct 08, 2010 4:47 am
Posts: 2
Actually I need remove not only '-' but all that goes after '-' too.
So if I have 'x11-base/xorg-server-1.7.7-r1' I should get 'x11-base/xorg-server'


Top
 Profile  
 PostPosted: Thu Oct 14, 2010 1:53 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
edrozim wrote:
Actually I need remove not only '-' but all that goes after '-' too.

It should be simple enough. Just add .* after the -.


Top
 Profile  
 PostPosted: Sat Jun 11, 2011 8:08 am   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
Why not just use bash(1) for such a task:

Code:
#!/bin/bash

while read -r p _; do
    if [[ $p != [* ]]; then
        pkgs+=("${p%-*}")
        pkgs=(${pkgs[@]%-[[:digit:].]*})
    fi 
done < <(equery d mesa)

printf -v list '%s ' "${pkgs[@]}"
<compile command> "${list%[[:blank:]]}"


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP