- Jun
- 73
- 2
Thought someone might like this:
Here is the source:
Enjoy!
Code:
[TCC]$ commify --help
commify - add commas to sequences of 4 consecutive integers, but only
to the non-decimal portion of a string of numbers
Usage: commify [-options] [file1 file2 ...]
Options:
-? = display this help message
-h = display this help message
-d = in the decimal portion, insert an underscore after every 3 digits
[TCC]$ echo Test (123456789012) (-098765.234580980) (+2389089808.99934) | commify
Test (123,456,789,012) (-098,765.234580980) (+2,389,089,808.99934)
[TCC]$ echo Test (123456789012) (-098765.234580980) (+2389089808.99934) | commify -d
Test (123,456,789,012) (-098,765.234_580_980) (+2,389,089,808.999_34)
Here is the source:
Code:
@echo off
:: filename: commify.btm
:: author: Eric Pement
:: date: 2012-04-16 14:38 CDT
if "%1" == "/h" .or. "%1" == "/?" .or. "%1" == "--help" goto syntax
:: locate sed -=[ CUSTOMIZE NEXT LINE ]=-
set SEDEXE=c:\enp\bin\sed.exe
if not exist %SEDEXE% goto no_sed
if "%1" == "-d" goto decimal
if "%1" == "" .and. %_pipe == 0 goto no_args
:main
%SEDEXE% -r ":a;s/(^|[^0-9.])([0-9]+)([0-9]{3})/\1\2,\3/g;ta" %$
goto end
:decimal
shift
%SEDEXE% -r ":a;s/(^|[^0-9.])([0-9]+)([0-9]{3})/\1\2,\3/g;ta; :b;s/\.([0-9]{3}_)*([0-9]{3})([0-9])/.\1\2_\3/;tb" %$
goto end
:no_sed
call error_beep.btm
echo ERROR! - Executable [%SEDEXE%] not found! Quitting ...
goto end
:no_args
call error_beep.btm
echoERR ` ERROR: No file to look for, nor values from STDIN!`
echoERR `SYNTAX: commify [-options] [file1 file2 ...]`
echo.
:syntax
TEXT
commify - add commas to sequences of 4 consecutive integers, but only
to the non-decimal portion of a string of numbers
Usage: commify [-options] [file1 file2 ...]
Options:
-? = display this help message
-h = display this help message
-d = in the decimal portion, insert an underscore after every 3 digits
ENDTEXT
:end
unset /q SEDEXE
Enjoy!