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

g4ur4v
  • 1,764
  • 8
  • 29
  • 34

1 Answers1

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