multiply data of a file by a factor

June 3, 2009 at 06:06:09
Specs: Linux i686
Hi, I need to make a shell script that multiply each line of my data file by the same factor, but I don't know how. For instance, I have a data file of this type, (only with much more lines):


and I want to multiply each line by 20, and make another file with the results. How can I make it? Thanks, I'd really appreciate some help.

See More: multiply data of a file by a factor

Report •

June 3, 2009 at 06:58:39
awk '{print $0*20}' file > newfile

Report •

June 3, 2009 at 06:59:46
I'll give you the pieces. First, my bash shell is 3.2 so it only does integer arithmetic so I use the bc utility to do the math: No error checking:


x=$(bc << NAILS
      ($line * 20)
echo $x

Second, this stub reads a file, line by line, and sends it to a new file:

while read line
   echo "$line"
done < datafile.txt > newfile.txt

I'll leave it to you to put them together

Report •

Related Solutions

Ask Question