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
Not sure what you meant by constant gap. If it is a column width for
foo
,bar
andbaz
, try%13s
, where 13 is minimum column width.I understand your question. Using another answer as a base for mine:
If you want to pad each of the PARAMs then just add a numerical argument to the printf and it will pad it out to that number of characters per field.
Pad by 20 characters: printf "%s [WARN] %20s %20s %20s"
date +"%d/%b/%G-%T"
foo bar bazExamples:
Longer...
Much Longer...
Try it on a console. It works.