Skip to content

Instantly share code, notes, and snippets.

@tuxfight3r
Last active February 8, 2023 16:56
Show Gist options
  • Select an option

  • Save tuxfight3r/72739e7b16dcc86b9782f184eb643267 to your computer and use it in GitHub Desktop.

Select an option

Save tuxfight3r/72739e7b16dcc86b9782f184eb643267 to your computer and use it in GitHub Desktop.

Revisions

  1. tuxfight3r revised this gist Feb 8, 2023. No changes.
  2. tuxfight3r created this gist Feb 8, 2023.
    22 changes: 22 additions & 0 deletions notes.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    ##### For environments where there is no full fledged printf. The below function does a pretty print of numbers with thousand separator
    ### function
    ```
    #converts given number to pretty format
    function pretty_num(){
    awk '{ len=length($0); res=""; for (i=0;i<=len;i++) { res=substr($0,len-i+1,1) res; if (i > 0 && i < len && i % 3 == 0) { res = "," res } }; print res }'|sed -e's/-,\(.*\)/-\1/g'
    }
    ```
    ### output
    ```
    admin$> printf "1\n10\n100\n1000\n10000\n100000\n1000000\n10000000\n100000000\n-100000\n" |pretty_num
    1
    10
    100
    1,000
    10,000
    100,000
    1,000,000
    10,000,000
    100,000,000
    -100,000
    ```