I need to do some “pretty” formatting of numbers with bash. I have a string of comma separated floating point numbers in scientific format (ie. either 3.14159 or 1.0601e-12) and I need to create a comma separated list where all numbers have as many characters. It isn’t very important whether spaces or zeros are used for filling (ie. ‘ 3.14’ and ‘3.140000’ both work). I tried using printf with “%.12f”, but that of course won’t work. I’m out of ideas (except for working on a character level, but that seems overly complicated)
I really appreciate the help.
If you just want to specify a constant number of characters in your output, you can use the field-width modifier. For example, to ensure each field has exactly 24 characters: