[awk] - how to insert an external variable

I want to incorporate the variable in the for statement as a column of my processed file. In the INCORRECT example below, it is $i which corresponds to the i in my for loop:

for i in x86_64 i686; do
  awk '{ print $1" "$4" "$5" "$i }'awk $file-$i > processed-$i.log
done

Thanks!

for i in x86_64 i686; do
     awk -v myI="${i}" '{ print $1, $4, $5, myI }'awk $file-$i > processed-$i.log 
done
1 Like

Thanks! I actually found the solution myself (choice of key words is critical to success) in this old thread.

for i in x86_64 i686; do
  awk -v arch=$i '{ print $1" "$4" "$5" "arch } ' $file-$i > processed-$i.log
done
for i in x86_64 i686; do
    while read a x x b c x
    do 
         echo $a $b $c $i 
    done < $file-$i > processed-$i.log
done

Useless use of awk when the shell can do the job :cool: