Skip to content

Instantly share code, notes, and snippets.

@dspinellis
Last active May 16, 2021 20:23
Show Gist options
  • Save dspinellis/e0cd63da39eb9346445495c9956d852e to your computer and use it in GitHub Desktop.
Save dspinellis/e0cd63da39eb9346445495c9956d852e to your computer and use it in GitHub Desktop.
Filter to add decimal separators to long numbers
#!/bin/sed -Ef
#
# Add a LaTeX thin space (\,) decimal separator to long digit sequences
#
# Diomidis Spinellis, October 2018
#
# Save this as a file and add it to your path, or run at as a one-liner:
# sed -E ':a;s/([0-9])([0-9]{3})([^0-9]|$)/\1\\,\2\3/g;ta'
#
:a
# Add a , after a digit followed by three digits followed by non-digit or EOL
s/([0-9])([0-9]{3})([^0-9]|$)/\1\\,\2\3/
# Try the replacement again if the replacement succeeded
ta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment