4

How to fix the positions of output string in shell using printf?

For example ,if I want to print text TEXT-A at position starting from third position from left and one more text TEXT-B at eleventh position from left,as shown below. enter image description here

1 Answer 1

5
printf '  %-8s%s\n' TEXT-A TEXT-B

And if you want to truncate the first text if it too long to fit:

printf '  %-8.8s%s\n' TEXT-A TEXT-B

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .