printf to format lines.

Hey, I'm trying to read printf(3) and seems I need to use the * WIDTH
but I'm not quite sure how to go about it.
there needs to be 3 fields per line, the lines read in from file looks like this:
JUICE - APPLE:JUST JUICE:7
MILK - CHOCOLATE:BREAKA:7
this needs to be output backwards with specific justification.

isle number - right justified field width 5
brand name left justified field width 30
product name left justified 30

as so:

    7 JUST JUICE                    JUICE - APPLE
    7 BREAKA                         MILK - CHOCOLATE

is this exactly the same as c++ if so
it should work like
printf("%*5d%30s%30s", arg3, arg2, arg1) or something like that... :stuck_out_tongue:

printf "%05d %30s %30s\n" "$arg3" "$arg2" "$arg1"

this gives output:

00007                      BREAKA                        MILK - CHOCOLATE

need to left justify breaka, and milk, and right justify 7, with no 0's
printf(3) says using * symbol ?

printf "%5d %30s %30s\n" "$arg3" "$arg2" "$arg1"

thnx, the %5d works, it makes it right justified as default, anyway to make the other two left justified?
damn man pages why couldn't they make them easier to understand :S

printf "%5d %-30s %-30s\n" "$arg3" "$arg2" "$arg1"

ok figured it out

"%5d %-30s %-30s\n"

aww beat me to it :smiley: