piping seq to printf for number formatting piping seq to printf for number formatting bash bash

piping seq to printf for number formatting


The printf command does not output a line break if you don't ask it to. Try:

seq 0 10 | xargs printf '%04d\n'

Note that you can achieve the same with just seq, since it allows specifying a printf-style format:

seq -f %04g 0 10


you don't need printf or xargs. seq has -f option:

kent$  seq -f '%04G' 100001000200030004000500060007000800090010


seq 0 10 | xargs printf "%04d\n"

The original question is missing the newline character at the end of the printf. Simply adding a newline character fixes the issue.