I would like to use printf (or something else?) to create a line of text that has varying column widths. This will be used to create a fixed width file (with varying column widths). For example, consider variables $1 $2 $3 are equal to a, b, c respectively and they should be printed in column positions 1, 5, 15 respectively so the output would be:
a___b_________c
(ignore the underlines)
I was thinking I could use awk for this but it isn't clear to me how I could use awk without a file input (I just want to be able to pass text or variables).
Any ideas would be greatly appreciated... maybe there's a simple perl command, a combination of multiple print commands, or something else I should be using?
Sorry, but that (post #2) won't yield a FIXED width file - which was part of the request - should the contents of $3 vary. You need to specify the third column output width as well, then.
EDIT: same applies to DGPickett's proposal, should $1 vary in length.
@RudiC: OP will figure it out, it was just an example. The post was more about using shell's printf instead of an external utility. Besides what if a value is wider than the intended width?
Although now I wonder if it is possible to align output to the right of the field rather than the left. For instance if ST is 6 (rather than 06), the first two spaces of output are "6 "rather than " 6". Is there a way to make it align right instead?
Thank you everyone for your very informative posts.