9

I have a .txt file with one column. it is about 8000 numbers. How can I multiply this column of data by 1000000?

  • 3
    If the numbers are strictly integers, then sed 's/$/000000/' file.txt – glenn jackman Jun 25 '18 at 19:17
  • 6
    @glennjackman: That looks like an answer. :-] – David Foerster Jun 25 '18 at 21:15
  • What if the numbers are not integers? – copper.hat Jun 26 '18 at 0:24
24

You can use awk command:

awk '{print $1*1000000}' file.txt
16

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
  • Should that be bc in the last command or is dc something else? – PerlDuck Jun 25 '18 at 17:57
  • 3
    @PerlDuck dc is something else - see for example How is bc different from dc? – steeldriver Jun 25 '18 at 18:02
  • LOL, I haven't read carefully enough and thought of polish as in make something shiny. Ty for explaining. – PerlDuck Jun 25 '18 at 18:06
  • 3
    Ha, so "reverse polish" is "to make something less shiny (more muddy)"? IMO, dc meets that requirement – glenn jackman Jun 25 '18 at 19:16
  • See this link, Wikipedia: Reverse Polish notation - This became popular in the 1970ies with the HP-35, the world's first handheld scientific calculator, and the following series of calculators. – sudodus Jun 25 '18 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.