You are not logged in.
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 }' $file-$i > processed-$i.log
done
Thanks!
EDIT: finally found the solution (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
Last edited by graysky (2011-11-27 15:11:08)
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
I don't get your use of quotes. Wouldn't
awk -v arch=$i '{ print $1 $4 $5 arch }'
work?
"$5" prints a literal "$5" here instead of what's in the 5th column.
Last edited by karol (2011-11-27 15:22:36)
Offline
Offline
The quotes are between the vars, not around them... better to use commas to separate:
awk -v arch=$i '{ print $1, $4, $5, arch }'
A great lesson in perspective and code readability.
Thanks!
Offline
@falconindy - I thought of that but I wanted to use spaces for this application. As you pointed out, the quotes are not to protect the vars, but to add the space between them.
@keenerd - just analyzing my unofficial repo log files to generate some statistics for users. BTW, expac looks pretty slick!
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
Offline