Hi,
I need to multiply 3rd column (comma seperated) of entire file by a value say 2.2.
Suppose the file is:
C,Gas $ YTD(TRI),15512.36,01/01/2010
New file should be (3rd column value multiplied by 2.2):
C,Gas $ YTD(TRI),34127.192,01/01/2010
Hi,
I need to multiply 3rd column (comma seperated) of entire file by a value say 2.2.
Suppose the file is:
C,Gas $ YTD(TRI),15512.36,01/01/2010
New file should be (3rd column value multiplied by 2.2):
C,Gas $ YTD(TRI),34127.192,01/01/2010
Whichever suitable:
awk -F, '{$3=$3*2.2;print}' OFS=, inputFile
OR
awk -F, '{$3=$3*a;print}' a=2.2 OFS=, inputFile
OR
awk -F, '{$3=$3*a;print}' a=$var OFS=, inputFile
Try
awk 'BEGIN{FS=OFS=","}{print $1,$2,$3*2.2,$4 }' file.txt
awk -F, '{$3=sprintf("%.2f",$3*2.2)}1' OFS=, infile
or if the precision does not need to be fixed:
awk -F, '{$3*=2.2}1' OFS=, infile
Should be:
awk -F, '{$3=sprintf("%.3f",$3*2.2)}1' OFS=, infile
.2 is only an example. The OP can choose what value he likes...