LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell scrpting - decreasing the decimals of numbers (https://www.linuxquestions.org/questions/linux-newbie-8/shell-scrpting-decreasing-the-decimals-of-numbers-4175507590/)

sryzdn 06-10-2014 07:24 AM

shell scrpting - decreasing the decimals of numbers
 
Hi,

I have columns like this:

Code:

 
        -1.67700444        -0.93558089        -0.03968523
        -1.67191856        0.95738334        2.48905615
        0.02711232        1.89308707        -0.04336284
        1.67950619        0.93385064        2.49129742

I want to reduce the decimals to 6 to have a result like this:

Code:

        -1.677004        -0.935580        -0.039685
        -1.671918        0.957383        2.489056
        0.027112        1.893087        -0.043362
        1.679506        0.933850        2.491297

Any ideas about how I can do this. Thaks for your guide...

pan64 06-10-2014 07:43 AM

probably with awk, using printf?

eklavya 06-10-2014 08:17 AM

I hope there are three columns only.
Code:

cat /path/of/file | awk '{printf "%.6f %.6f %.6f\n", $1, $2, $3}'

pan64 06-11-2014 12:12 AM

just please do not use cat: awk 'script' filename would be better


All times are GMT -5. The time now is 09:33 PM.