1

Trying to re-format a column, but I need to add decimals to the price and need to be align to the right. It also needs leading white spaces at end in order to work with other column.

awk -F, '{print $6}' $FILE | awk '{printf("%-7s\n", $0) }' > $TEMP/unit_price

current output:

99
121.5
108
67.5

This is how I need it to look like and align to the right:

  99.00
  63.00
 121.50
 108.00
 108.00
  67.50
 67.50
1
  • 6
    You probably want a format specifier like %7.2f rather than %-7s Dec 22 '16 at 0:41
2
  • 1 awk is enough for all your treatment
  • %s convert your number to a string basically, use another format converter like %f for float in this case

    awk -F ',' '{printf("%3.2f\n", $6}' ${FILE} > ${TEMP}/unit_price
    

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.