drwxr-xr-x 1,653 dalke admin 56,202 Mar 5 2,012 pubchem
-rw-r--r-- 1 dalke staff 59,252 Nov 16 2,011 pubchem_10,000.fps.0.9.cluster
I don't want to see the year written "2,012", and the file name is 'pubchem_10000" not "pubchem_10,000".EDIT: seeing how it has been downvoted, IMHO hacking is all about time and effectiveness. if you believe fixing ls print formats is such a crucial problem that it requires more than seconds of your time, we have different values.
Feel free to support the argument by showing your skills and improving the example.
It is exactly about showing how hard it is to get a trivial change right in every detail. Your 10 second hack is what is wrong with 10 second hacks in general and even with most real solutions that are not carefully thought out.
It's not only that the devil is in the details it is all details. And you need to get all of them right, not just the current subset of the problem that you happen to be working on.
Someone with command line experience that is mostly a user of system utilities would think passing the output of ls through a filter is the way to go whereas someone with C experience that already has insight in how Unix is architected would do something more along the lines of what the author is doing. That's pretty much how unix got built to begin with, and probably both parties would qualify their solution as a 'hack'.
It's all perspective.
(Note that this RFC comes from the days when 'hacker' was becoming a widespread term for someone who breaks into computer systems; the RFC attempts to distinguish between a 'hacker' and a 'cracker.')
https://github.com/samsonjs/bin/blob/master/ls-comma
It's a disgusting hack and it works very well. I didn't find anything useful in the man page so I wrote this instead. Looks like there is something in the man page but I think my hack was probably faster.
correction: sorry it will only fix the modifications to the filename - the year is still broken.
ls -l | perl -pe 'while(s/^((\S+\s+){4})(\d+)(\d{3})([^\d].*)?$/$1$3,$4$5/){}' -rw-r--r-- 1 root wheel 16,596,907,252 24 Dec 2009 boskoop.disk0.bz2
-rw-r--r-- 1 grog wheel 4,173,914,809 20 Jul 2006 boskopp.tar.gz
With your perl one-liner on my directory I get mis-aligned columns: -rw-r--r-- 1 dalke staff 3,236,397,056 Sep 13 2011 pubchem.fps
-rw-r--r-- 1 dalke staff 712,181,172 Sep 13 2011 pubchem.fps.gz
That's ugly. It should be: -rw-r--r-- 1 dalke staff 3,236,397,056 Sep 13 2011 pubchem.fps
-rw-r--r-- 1 dalke staff 712,181,172 Sep 13 2011 pubchem.fps.gz
But I still wonder if this is easier than ls -l | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' ??
The investigations would be interesting it they were more complete, i.e. if the actual result was a change in the locale which could be appliable to other tools printing numbers besides ls (in the author TODO).
I mean, will it work with bc?
At the moment it's not better than an shell script alias giving the output to sed, but it is more complex - you have to recompile a binary for every OS you use.