[Sunhelp] commas in ls output

Stu Slimp stuslimp at austin.technow.com
Tue Jun 29 10:39:59 CDT 1999


--------------6F8D508BB14E3F2CF4A40120
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Steve Mynott wrote:

> I want commas in the numeric part of 'ls' output and think this should
> be possible from setting LC_NUMERIC?
>
> Does anyone know how to do this?

LC_NUMERIC is not referenced by many, if not all, versions
of ls.  I use the following script:

# ls -l with commas in size field (field number 5)

ls -l $* |
awk '
BEGIN { fnum = 5 }
{
    str = ""
    start = "1"
    flen = length($fnum)
    size = flen % 3
    if (size == 0)
        size = 3
    if (flen > 3) {
        while (start <= flen - 3) {
            str = str substr($fnum, start, size) ","
            start += size
            size = 3
        }
        str = str substr($fnum, start)
    }
    else
        str = $fnum
    $fnum = str
    printf("%s %3s %-8s %-8s %12s %3s %2s %5s %s\n", \
        $1,$2,$3,$4,$5,$6,$7,$8,$9)
}'

Stu Slimp

--------------6F8D508BB14E3F2CF4A40120
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
Steve Mynott wrote:
<BLOCKQUOTE TYPE=CITE>I want commas in the numeric part of 'ls' output
and think this should
<BR>be possible from setting LC_NUMERIC?

<P>Does anyone know how to do this?</BLOCKQUOTE>
LC_NUMERIC is not referenced by many, if not all, versions
<BR>of ls.  I use the following script:
<PRE><FONT FACE="Courier New,Courier"># ls -l with commas in size field (field number 5)

ls -l $* |
awk '
BEGIN { fnum = 5 }
{
    str = ""
    start = "1"
    flen = length($fnum)
    size = flen % 3
    if (size == 0)
        size = 3
    if (flen > 3) {
        while (start <= flen - 3) {
            str = str substr($fnum, start, size) ","
            start += size
            size = 3
        }
        str = str substr($fnum, start)
    }
    else
        str = $fnum
    $fnum = str
    printf("%s %3s %-8s %-8s %12s %3s %2s %5s %s\n", \
        $1,$2,$3,$4,$5,$6,$7,$8,$9)
}'</FONT>
</PRE>
Stu Slimp<BR>
<BR></HTML>

--------------6F8D508BB14E3F2CF4A40120--






More information about the SunHELP mailing list