Re: [SLUG] quoting

From: Eben King (eben1@tampabay.rr.com)
Date: Fri Dec 16 2005 - 18:15:33 EST


On Fri, 16 Dec 2005, Bill Glidden wrote:

> On 12/16/05 4:07 PM, "Eben King" <eben1@tampabay.rr.com> wrote:
>
> > OK, I'l having a quoting problem. Not people taking things out of context,
> > or using quotes without attribution, shell quoting. What I want is the "du
> > -sh"-style output, only sorted by size. The only way I can see to do that
> > is to get the "du -s"-style output, sort it, trim off the size, and call "du
> > -sh' on each one. Rather inefficient, but I don't see a better way.
> > (Sorting "du -sh"'s output will put "100M" before "200K".)
> >
> ..snip..
>
> > What am I doing wrong, and what's the right way to do it? Thanks.
>
> Have you tried
>
> PP='cut -f 2- -d " "'
>
> echo "some stuff" | eval $PP

<penny drops>

Ah, it's a tab after the size, not a series of spaces. But even with your
suggestion, it's the same deal:

[eben@pc eben]$ ddu -h /export/media/*
+ du -s /export/media/backgrounds /export/media/ferret-legging.txt
/export/media/images /export/media/midi /export/media/mod
/export/media/movie /export/media/mp3 /export/media/palette.64.gif
/export/media/palette.64.ppm /export/media/patterns
/export/media/root.cache.980907 /export/media/sounds /export/media/temp
+ sort -n
+ sed 's@ \./@ @'
+ eval cut -f 2- -d '"' '"'
++ cut -f 2- -d ' '
4 /export/media/palette.64.gif
4 /export/media/palette.64.ppm
4 /export/media/root.cache.980907
16 /export/media/ferret-legging.txt
442 /export/media/patterns
1413 /export/media/mod
16240 /export/media/midi
31731 /export/media/temp
159625 /export/media/sounds
422843 /export/media/backgrounds
1732338 /export/media/movie
4014387 /export/media/images
5605004 /export/media/mp3

And I made sure that in the script is a tab, not spaces:

                    vv-----------------space------------------v
0000620 2d 20 2d 64 20 22 09 22 27 0a 23 5c 7c 20 77 68 >- -d "."'.#\| wh<
                          ^^------------------tab---------------^

What I want to see is this:

[eben@pc eben]$ du -s /export/media/* | sort -n | cut -f 2- -d " "
/export/media/palette.64.gif
/export/media/palette.64.ppm
/export/media/root.cache.980907
/export/media/ferret-legging.txt
/export/media/patterns
/export/media/mod
/export/media/midi
/export/media/temp
/export/media/sounds
/export/media/backgrounds
/export/media/movie
/export/media/images
/export/media/mp3

Then I can pipe that sorted list through some stuff to get each element's
size.

::tnme passes::

OK, I have a winner:

TAB=" "
PP='cut -f 2- -d "$TAB"'
...
du -s "$@" \
| sort -$SORT_ARGS \
| sed 's@ \./@ @' \
| eval $PP ;;

Jeez, what a PITA.

-- 
-eben    ebQenW1@EtaRmpTabYayU.rIr.OcoPm    home.tampabay.rr.com/hactar
ARIES:  The look on your face will be priceless when you find that 40lb
watermelon in your colon.  Trade toothbrushes with an albino dwarf, then
give a hickey to Meryl Streep.  -- Weird Al, _Your Horoscope for Today_

----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:56:34 EDT