pkgsrc tips (Was Re: Proper choice of package management strategy)

Amadeus amadeus.stevenson at
Sun Jan 21 07:10:54 PST 2007

Zeb Packard wrote:
> On 1/20/07, Nadav Vinik <nadavvin at> wrote:
>> Do you have script like that?
>> since It user readable but it harder to parse in simple regular expression:
>> $ ldd /bin/bash
>> =>  (0xffffe000)
>> => /lib/ (0xb7f6c000)
>> => /lib/ (0xb7f64000)
>> => /lib/ (0xb7f22000)
>> => /lib/ (0xb7f1e000)
>> => /lib/ (0xb7df4000)
>>        /lib/ (0xb7fb7000)
> No I don't but,
Without understanding why you want this, a quick stab with (g)awk and 
sed leads to:

$ ldd `which bash` | sed -e 's/([^ ]*)//' -e 's/ //g' | awk -F=\> 
'$2!="" {print $2}'

Where /lib/ and are ignored.

The first sed expression removes the (0xb7f6c000) part.
The second sed expression removes whitespace (so you don't get blank 
lines with awk later).
The awk -F=\> specifies a field separator of => (the default is " ").
The rest of the awk will show the second term of an input line split by 
=> (ie. the bit we want), if this is not empty

I'm no sed/awk guru so it might be possible to clean this up, although 
as it is, for me, this qualifies as a "one-liner" :)

If you want the output to be alphabetical pipe the above to `sort`.

If you want this in a script (with sorting) try:



if [ -r "$1" ]; then
    $LDD $1 | $SED -e 's/([^ ]*)//' -e 's/ //g' | $AWK -F=\> '$2!="" 
{print $2}' | $SORT

Where the if [ -r "$1" ] bit checks if the argument passed to the script 
is a readable file.



More information about the lfs-support mailing list