0

I would like to multiply a single column in a .txt file by a variable and then write to another .txt file. What am I missing from the awk line? Appreciate any help in advance.

!/bin/bash

FILES=/path/to/files
for f in ${FILES}
do
    echo $f
    wc -l $f
    B=10000000
    TOTALLINES="$(wc -l $f | cut -f1 -d' ')"
    echo "TOTALLINES: ${TOTALLINES}"
    SCALINGFACTOR=$(echo "100000000 / $TOTALLINES" | bc -l)
    echo "scaling_factor:  ${SCALINGFACTOR}"
    awk '{printf($1"\t"$2"\t"$3"\t"$4 * "${SCALINGFACTOR}")}' $f"_prepped.txt" > $f"_normalized.txt"

done
Stephen
  • 141

1 Answers1

1

Inside awk you don't have direct access to shell variables, you need to pass them as an options, so change awk command to something like:

awk -v SF="$SCALINGFACTOR" '{printf($1"\t"$2"\t"$3"\t"$4*SF)}'
jimmij
  • 47,140