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

u at netbeisser.de u at netbeisser.de
Mon Jun 6 14:37:49 CEST 2011


Hi Dag,

On Mon, Jun 06, 2011 at 02:03:27AM +0200, Dag Wieers wrote:
> On Sun, 5 Jun 2011, u at netbeisser.de wrote:
 
> >> +		$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
 
Ok, so it turns out to be more ugly.


> 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.
 
I like the awk version for the better readability.

> # 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
 
Hm, I came up with the idea of parsing : in ldd -v, but you get other problems. narf.
FWIW, for me awk is "faster":

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

real    0m0.774s
user    0m0.133s
sys     0m0.083s

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

real    0m0.806s
user    0m0.157s
sys     0m0.080s


Kind Regards,
Stefan

-- 
--
Stefan Kuttler ==*== nc.netbeisser.de




More information about the rear-users mailing list