-
-
Save djeraseit/f24e009764e19a550bdd400ae3b2dc20 to your computer and use it in GitHub Desktop.
A one-liner sed expression to nicely strip leading and trailing 0's from each line of piped input
This file contains 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
################################################################################ | |
# ... | __zero_strip | |
################################################################################ | |
# | |
# Zero Strip | |
# | |
# A one-liner sed expression to nicely strip leading and trailing 0's from each | |
# line of piped input. | |
# | |
# For example: | |
# | |
# echo '1.0 | |
# 5.000 | |
# 9.0001 | |
# 50.60 | |
# 7.24235 | |
# .9000 | |
# .00001' | __zero_strip | |
# | |
# Generates: | |
# | |
# 1 | |
# 5 | |
# 9.0001 | |
# 50.6 | |
# 7.24235 | |
# 0.9 | |
# 0.00001 | |
# | |
################################################################################ | |
__zero_strip () { | |
cat | sed -e 's|\(\..*[^0]\)0\{1,\}$|\1|' -e 's|\.0*$||' -e 's|^0*||' -e 's|^\.|0.|' -e 's|^$|0|' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment