Math operations with file columns values.

Hello everybody,

I have some large files containing statistical data. The data is stored in the following generic format:

>cat my_file
1, 2, 3
1, 2, 3
1, 2, 3

>

The values of columns no.2 and 3 are expressed in bytes. I would like to transform them in Megabytes, by dividing them with 1048576. How could I do that automatically?

Thank you,
fabian

 
$ nawk -F, '{print $1","$2/1048576"MB,"$3/1048576"MB"}' test                                                                                      
1,1MB,1MB
2,2MB,2MB
3,2MB,2MB

$ cat test
1,1048576,1048576
2,2097152,2097152
3,2097152,2097152

---------- Post updated at 01:25 PM ---------- Previous update was at 01:24 PM ----------

if you want to test handle some floating points in output, then try printf

Thank you very much for your quickly reply.
Right, but I forgot to tell that I would like to save them in a new file.
What is the option for that?

fabian

 
nawk -F, '{print $1","$2/1048576"MB,"$3/1048576"MB"}' input > output
1 Like