This line of code:
printf 'ddd %-22s dddd \n' "eeeeeee"
Aligns to the left.
What could I use to align it to centre like this:
ddd      eeeeeee      dddd
                A bit tricky ... but what about this? ;)
STR="eeeeeee"; printf 'ddd %11s%-11s dddd \n' `echo $STR | cut -c 1-$((${#STR}/2))` `echo $STR | cut -c $((${#STR}/2+1))-${#STR}`
                        printf not support it, but easy to implement it:
D="12"    # input string
BS=10     # buffer size
L=$(((BS-${#D})/2))
[ $L -lt 0 ] && L=0
printf "start %${L}s%s%${L}s end\n" "" $D ""
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With