LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   is there a way to list all packages by size? (https://www.linuxquestions.org/questions/slackware-14/is-there-a-way-to-list-all-packages-by-size-872616/)

Ramurd 04-03-2011 03:20 PM

because awk is not built for speed; it's in fact quite slow, but does support alot of otherwise useful features. :-) nice script!

kjhambrick 04-03-2011 04:05 PM

Thanks Ramurd.

What I found baffling was that I expected the get-pkgsize
script to take longer than the simple awk one-liner because
get-pkgsize is a gawk script in a shell-wrapper with which
pipes output to sort then to another gawk script.

Anyhow ...

-- kjh(<G> it's not like the real delta-t's are significant in any case <G>)

kjhambrick 04-03-2011 04:09 PM

p.s. I use gawk every day for some serious data conversions( GB's of Data )
and I have found that the speed is close enough to perl's speed that I choose
gawk over perl because I can use code-generators I've developed over the past
30-years :)

mRgOBLIN 04-04-2011 05:37 AM

Nice (g)awk kjhambrick.

Good to see someone use awk for something other than '{ print $1 }' for a change.

kjhambrick 04-04-2011 06:43 AM

Thanks mRgOBLIN !

I really do like gawk's syntax. It's quite capable of any text processing that I have ever thrown at it.

I did figure out why get-pkgsize was so much faster than audriusk's original awk one-liner ...

The get-pkgsize script invokes nextfile as soon as it finds the /^UNCOMPRESSED/ pattern in the stream

OTOH, the awk one-liner scans the rest of each the files in /var/log/packages, looking for more instances
of the pattern in each line.

These are the times again. Note that the new one-liner with nextfile is about as fast as the grep pipeline.

-- kjh

p.s. not that the times of 0.02 secs vs 0.14 secs mean anything in the real world where the one-liner will be invoked :)


Code:

# gnashley's fgrep suggestion:

[konrad@kjhlt5 compat32pkg]$ time fgrep UNCOMPRESSED /var/log/packages/* | awk -F: '{print $3,$1}' | LC_ALL=C sort -rh > /dev/null

real    0m0.020s
user    0m0.009s
sys    0m0.017s

# fskmh's grep approach with audriusk's LC_ALL=C and sort -rh

[konrad@kjhlt5 compat32pkg]$ time grep UNCOMPRESSED /var/log/packages/* | awk -F: '{print $3,$1}' | LC_ALL=C sort -rh > /dev/null

real    0m0.022s
user    0m0.015s
sys    0m0.016s

# audriusk's original awk one-liner

[konrad@kjhlt5 compat32pkg]$ time awk -F: '/UNCOMPRESSED/ {print $2,FILENAME}' /var/log/packages/* | LC_ALL=C sort -rh > /dev/null

real    0m0.137s
user    0m0.131s
sys    0m0.014s

# audriusk's original awk one-liner with nextfile after match

[konrad@kjhlt5 compat32pkg]$ time awk -F: '/^UNCOMPRESSED/ {print $2,FILENAME ; nextfile }' /var/log/packages/* | LC_ALL=C sort -rh  > /dev/null

real    0m0.022s
user    0m0.011s
sys    0m0.016s

# get-pkgsize (also invokes nextfile )

[konrad@kjhlt5 compat32pkg]$ time get-pkgsize  > /dev/null

real    0m0.040s
user    0m0.028s
sys    0m0.019s

# since we're being anal about runtimes <G>, here's grep with the -m1 arg:

[konrad@kjhlt5 compat32pkg]$ time grep -m1 UNCOMPRESSED /var/log/packages/* | awk -F: '{print $3,$1}' | LC_ALL=C sort -rh > /dev/null

real    0m0.014s
user    0m0.005s
sys    0m0.015s

# and here's fgrep with the same -m1 flag

[konrad@kjhlt5 compat32pkg]$ time fgrep -m1 UNCOMPRESSED /var/log/packages/* | awk -F: '{print $3,$1}' | LC_ALL=C sort -rh > /dev/null

real    0m0.018s
user    0m0.009s
sys    0m0.022s


allend 04-04-2011 09:51 AM

Quote:

# since we're being anal about runtimes
OMG, not me. Just posted my observation after a few trials on an idle whim.
Thankyou for the insightful investigation and explanation.
Quote:

not that the times of 0.02 secs vs 0.14 secs mean anything in the real world where the one-liner will be invoked
So true! I cannot blink that fast.

szboardstretcher 04-04-2011 03:05 PM

Quote:

Originally Posted by prol (Post 4311820)
pkgtool just lists it in alphabetical order.

Thanks

If slakware had RPM, you could use:

Code:

rpm -qa --queryformat="%{size} %{name}-%{version}-%{release}\n" | sort -rn

brixtoncalling 04-04-2011 03:09 PM

Quote:

Originally Posted by szboardstretcher (Post 4313808)
If slakware had RPM, you could use:

Code:

rpm -qa --queryformat="%{size} %{name}-%{version}-%{release}\n" | sort -rn

And if ArchLinux used apt-get then you could ... Talk about unhelpful posts.

kjhambrick 04-04-2011 04:24 PM

And I wouldn't have had all the fun I had writing get-pkgsize :)


All times are GMT -5. The time now is 08:17 PM.