Possible Duplicate:
ksh + printf stat gap of print

I need to print the following values with printf as the follwoing around like this:

printf "[date +%d"/"%b"/"%G"-"%T] [WARN] $PARAM1 $PARAM2 $PARAM3

The required output:

[02/Jun/2010-11:08:42] [WARN] val1....val2...val3

the gap between val1 to val2 and from val2 to val3 must be const gap not depend the length of the values

link|improve this question

36% accept rate
Your question was already answered here. – Dennis Williamson Jun 2 '10 at 11:10
feedback

closed as exact duplicate by Dennis Williamson, Doug Harris, heavyd, Phoshi, Ivo Flipse Jun 4 '10 at 9:48

This question covers exactly the same ground as earlier questions on this topic; its answers may be merged with another identical question. See the FAQ for guidance on how to improve it.

1 Answer

You can specify field widths for printf. Here are examples of printing numbers (spaces or zeros as prefix) and strings (left or right justified):

$ printf "[% 10d]" 1
[         1]

$ printf "[%010d]" 1
[0000000001]

$ printf "[%10s]" test
[      test]

$ printf "[%-10s]" test
[test      ]
link|improve this answer
feedback

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