[Rear-users] SF.net SVN: rear:[556] trunk/usr/share/rear/lib/linux-functions.sh

Dag Wieers dag at wieers.com
Mon Jun 6 02:03:27 CEST 2011


On Sun, 5 Jun 2011, u at netbeisser.de wrote:

>> @@ -202,28 +199,29 @@
>>  	StopIfError "Unable to find a working ldd binary."
>>
>>  	local initrd_libs=( $(
>> -		$ldd "$@" \
>> -		| sed -ne 's:\t\(.* => \)\?\(/.*\) (0x[0-9a-f]*):\2:p'
>> +		$ldd "$@" | sed -ne 's:\t\(.* => \)\?\(/.*\) (0x[0-9a-f]*):\2:p' | sort -u
>>  	) )
>
> I think the sed in initrd_libs function can be replaced by a simple awk '{print $1}'

Not quite, the output of ldd contains 4 types of entries, of which only 
two need to be printed:

  1. The original library (when more than one argument is provided to ldd)
       -> no need to print, as already included
  2. Lines with "	=>  (memory address)"
       -> no need to print
  3. Lines with "	lib => /path/lib (memory address)"
       -> print $3
  4. Lines with "	/path/lib (memory address)"
       -> print $1

So if you like to change it into an awk, it needs to become something 
like:

     awk '/^\t.+ => \// {print $3} /^\t\// {print $1}'

certainly more readable. Not sure if it is any faster, testing both on my 
laptop is not conclusive, sometimes sed is faster, sometimes awk. Likely 
it depends on disk I/O more than on sed or awk.

# time ldd /bin/* /lib64/*.so* | sed -ne 's:\t\(.* => \)\?\(/.*\) (0x[0-9a-f]*):\2:p' | sort -u | wc -l
83

real    0m1.887s
user    0m0.842s
sys     0m1.588s

# time ldd /bin/* /lib64/*.so* | awk '/^\t.+ => \// {print $3} /^\t\// {print $1}' | sort -u | wc -l
83

real    0m1.879s
user    0m0.756s
sys     0m1.631s

Kind regards,
-- 
-- dag wieers, dag at wieers.com, http://dag.wieers.com/
-- dagit linux solutions, info at dagit.net, http://dagit.net/

[Any errors in spelling, tact or fact are transmission errors]




More information about the rear-users mailing list