[Gllug] Downright fun
Nix
nix at esperi.demon.co.uk
Thu Mar 13 21:44:09 UTC 2003
On Sat, 8 Mar 2003, David Pashley uttered the following:
> Allen Baranov said, and I quote:
>> On Tuesday 04 March 2003 18:21, Rev Simon Rumble wrote:
>> > John reminded us that Linux is "downright fun". So what are the fun
>> > things you've discovered/built/got working under Linux recently?
>>
>> Ok, just to be different and test the limits of the question I choose "|"
>> (pipe).
>>
>> I love stringing commands together to get results which is something Unix was
>> built for. Failing that - perl.
>
> I could scare you with bash one liners. ;)
Bah.
Beat this for ugliness:
,----
| #!/bin/ksh
| #
| # Clean up the duplicated junk from the CPAN directories.
| #
|
| CPAN=/usr/packages/perl/modules/CPAN
|
| integer NUMSLASHES
|
| NUMSLASHES=`echo $CPAN | sed 's,[^/],,g' | wc -c`+6
|
| # This for condition gives us a list of module names of dupped modules, absent their version number and path.
| # (It'll break with a module named e.g. Foo-77.Men-Alive-0.22, but I think we can cope with that.)
|
| for name in `find $CPAN/authors/id -type f -name "*.tar.gz" | sed 's,^.*/\([^/]*\)$,\1,; s/^\(.*\)-[0-9]*\..*$/\1/' | sort | uniq -c | sort -n -k 1 | grep '^[[:space:]]*[2-9]' | awk '{ print $2; }'`; do
|
| # We now have a name. Find all perl modules that match that name, sort them by basename, and tear the last line off. Zap everything else.
|
| find $CPAN/authors/id -type f -regex '^.*/'$name'-[0-9.]*\.tar\.gz$' | sort -t / -k $(($NUMSLASHES+1)) | tac | tail +2 | tac | xargs rm -f
| done
`----
(Use perl in a program that would be useless without perl? Naturally
not; that would be *sane*. ;} )
--
#ifdef USE_ISPTS_FLAG
} else { /* else pty, not pts */
#endif
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list