Bash script Multiply only numbers from a text file?

I am looking for a bash command that will multiply only numbers from a text file. Below is the content of my text file. I need multiply all numbers by 100.

    0 4530000 sil
4530000 11100000 ow
11100000 6320000 p
6320000 7600000 ah
7600000 8410000 n
8410000 12100000 sil

For single line with only number,I am using something like this below

for file in *.txt; 
do y=`sed -n '1 p' "$file"`;
   z=$(bc<<<"$y*100")
   sed $file -i -e 's/'"$y"'/'"$z"'/'
done

But I dont know how to do it for multiple lines, with alphabets in them. Number of lines in my file are not fixed, each file has different number of lines with max being 8

Answer

Can use perl

perl -pe 's/b(d+.)?d+b/$&*100/ge' file

Leave a Reply

Your email address will not be published. Required fields are marked *