Created
October 7, 2025 12:30
-
-
Save countingpine/69c5c700a74a36af48014560e228a0b8 to your computer and use it in GitHub Desktop.
Add commas to numeric strings in data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # add commas to all numbers in piped data (four digits or more, no leading '.') | |
| sed -E ' | |
| :a # (repeat label) | |
| s/(([^.0-9]|^)[0-9]+)([0-9]{3})([^0-9]|$)/\1,\3\4/; # replace nnn...nnn with nnn...,nnn (if no decimal point before the start) | |
| t a # repeat until no more matches | |
| ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment