Results 1 to 8 of 8

Thread: Include thousand separator in linux terminal

  1. #1
    Join Date
    May 2011
    Beans
    63

    Include thousand separator in linux terminal

    Hello.

    How can I include the thousand separator when I'm listing directory contents?
    I would also like that setting to be system-wide.

    So instead of this:
    Code:
    ls Documents -l
    -rwxrwxrwx user user 123456789 Files.txt

    I would like to obtain this:
    Code:
    ls Documents -l
    -rwxrwxrwx user user 123.456.789 Files.txt

    Thank you
    Binary-Synapse

  2. #2
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Include thousand separator in linux terminal

    At least, you can
    Code:
    $ ls -hl Documents
    -rwxrwxrwx 1 user user 117M ... Files.txt
    Last edited by schragge; March 19th, 2013 at 02:21 PM.

  3. #3
    Join Date
    May 2011
    Beans
    63

    Re: Include thousand separator in linux terminal

    Hello,

    Yes the 'h' switch is nice when you want to read it in 'human-format'.

    But the purpose would be to include the thousand separator, to make it more easy to read the exact size of a specific file.
    Binary-Synapse

  4. #4
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Include thousand separator in linux terminal

    Then try
    Code:
    ls -log --time-style=+|sed -r 's/^[^ ]* *[^ ]* *//;s/ +/\t/;:l;s/(.*[0-9])([0-9]{3}[,\t])/\1,\2/;tl'
    or, if your login shell is bash (would also work with ksh93, pdksh, or with any shell if using /usr/bin/printf from GNU coreutils)
    Code:
    ls -log --time-style=+|while read -r p l s n;do printf "%'15d %s\n" $s "$n";done
    Last edited by schragge; March 21st, 2013 at 03:45 PM.

  5. #5
    Join Date
    May 2011
    Beans
    63

    Re: Include thousand separator in linux terminal

    Hello.

    It works.
    Huge commands though...

    Thank you schragge
    Binary-Synapse

  6. #6
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Include thousand separator in linux terminal

    Well, the first one may be shortened a bit if you don't mind all the other data you'll get with ls -l:
    Code:
    ls -l|sed -r 's/ +/\t/5;:l;s/(.*[0-9])([0-9]{3}[,\t])/\1,\2/;tl'
    For the second, the following also should work, but it makes the command only marginally shorter
    Code:
    ls -log|while read -r p l s r;do printf "%'15d %s\n" $s "$r";done
    Last edited by schragge; March 21st, 2013 at 03:49 PM.

  7. #7
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Include thousand separator in linux terminal

    FYI, the GNU coreutils 8.21 sport a new command numfmt, hopefully to be included in Ubuntu after raring.
    Last edited by schragge; March 23rd, 2013 at 11:31 PM.

  8. #8
    Join Date
    May 2011
    Beans
    63

    Re: Include thousand separator in linux terminal

    Hi schragge

    That really is a nice feature, to include in a near future.

    I have always had trouble reading exact file sizes from Linux terminals.

    Thanks for sharing.
    Last edited by Binary-Synapse; March 26th, 2013 at 01:49 PM.
    Binary-Synapse

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •