How to multiply a .txt data file by a constant number?
I have a .txt file with one column. it is about 8000 numbers. How can I multiply this column of data by 1000000?
You can use awk
command:
awk '{print $1*1000000}' file.txt
If the numbers in the file are integers or simple floating-point values, you could use the numfmt
utility with --from-unit=
to indicate the desired scaling.
Ex. given
$ cat file
1.23
5
3.45
17
6.78
23
then
$ numfmt --from-unit=100000 < file
123000.00
500000
345000.00
1700000
678000.00
2300000
You can add a variety of printf
-style formating to the output e.g.
$ numfmt --from-unit=100000 --format="%'12.2f" < file
123,000.00
500,000.00
345,000.00
1,700,000.00
678,000.00
2,300,000.00
Alternatively, with sed
and bc
:
sed 's/$/ * 100000/' file | bc
or (reverse polish variant)
sed 's/$/ 100000 * p/' file | dc