Find the answer to your Linux question:
Results 1 to 3 of 3
Hello guys I need to find a way to modify my file so I have my first number with 3 decimal points, comma, space and then my second number 3 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    4

    Decimal points


    Hello guys

    I need to find a way to modify my file so I have my first number with 3 decimal points, comma, space and then my second number 3 decimal points too.

    This is an example of my file:
    12,10.026
    8,6.35
    5,5.83
    11,7.87

    And I need this output:
    12.000, 10.026
    8.000, 6.350
    5.000, 5.830
    11.000, 7.870

    I think I can use something like: printf "%0.3f\n"
    but how can I create a script that can read the whole file and save it in the output format I need?

    Thanks a lot for your help

  2. #2
    Just Joined!
    Join Date
    Aug 2011
    Posts
    51
    You could use awk.
    awk -F\, {printf("%.3f, %.3f\n",$1,$2)}' yourfile

  3. #3
    Just Joined!
    Join Date
    Oct 2008
    Posts
    4
    That works great!

    Thanks a lot!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •