Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2017/05/05

One! One New Utility! Bwa-ha-hahaha!

Classic unix utilities give you a number of great tools, and you can use sed and awk and bash when those aren't enough.

But sometimes ...

I use ~ as a scratch space all too often, which leaves me with a huge amount of files that I stopped playing with a while ago. I can get to the point of knowing what types, sure, as I show here.

$ ls *.* | awk -F. '{ print $NF }' 
jpg
jpg
jpg
jpg
txt
txt
txt
pl
txt
txt
pl
txt
pl
pl
txt
html
pl
pl
gz
mp3
pl
pl
pl
pl
txt
pl
pl
sh
sh
txt
pl
pl
diff
txt
txt
txt
pl
txt
pl
txt
txt
txt
txt
py
...

But this only gets you so far. I can sort and know that there's a LOT of Perl files, perhaps too many, but nothing was immediate about telling me how many.

But hey, I am a programmer, so I wrote a solution.

#!/usr/bin/env perl
use feature qw{ say state } ;
use strict ;
use warnings ;
my %hash ;
my @list = @ARGV ;
if ( !scalar @list ) {
while (<STDIN>) {
chomp ;
push @list, $_ ;
}
}
for my $e (@list) {
$hash{$e}++ ;
}
say join "\n",
map { join "\t", $hash{$_},$_ }
grep {/\w/}
keys %hash ;
exit ;
__DATA__
Copyright (C) 2017 Dave Jacoby
All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself,
either Perl version 5.18.0 or, at your option, any later version of Perl 5 you may have available.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See either the GNU General Public License or the Artistic License for more details.
view raw count hosted with ❤ by GitHub
And here it is in a shell, combined with sort in order to give me the numbers, which includes a lot of throwaway Perl programs.

$ ls *.* | awk -F. '{ print $NF }' | count | sort -nr

95 pl
59 txt
10 sh
10 jpg
8 py
6 html
6 csv
5 js
2 gz
2 diff
1 zip
1 ttf
1 tt
1 svg
1 sql
1 Rd
1 R
1 pub
1 png
1 pdf
1 mp4
1 mp3
1 log
1 json
1 foo
1 conf
1 cnf


I suppose I need to do some cleanup in $HOME today...

No comments:

Post a Comment