Skip to content

Instantly share code, notes, and snippets.

@countingpine
Created October 7, 2025 12:30
Show Gist options
  • Select an option

  • Save countingpine/69c5c700a74a36af48014560e228a0b8 to your computer and use it in GitHub Desktop.

Select an option

Save countingpine/69c5c700a74a36af48014560e228a0b8 to your computer and use it in GitHub Desktop.
Add commas to numeric strings in data
#!/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