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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.