awk - Using an array of strings in gawk command in Linux -


i'm having problems applying gawk command array of strings.

the gawk command in works fine:

$ gawk '$1 == "name" {print $0}' data1.txt >> data2.txt  

with able find resembles word 'name' in column 1 of first data file, , copypaste whole line second data file.

however, have procedure couple of times, , when trying following, doesn't seem retrieve anything:

$ array=("name1" "name2") $ in "${array[$@]}"; gawk '$1 == $i {print $0}' data1.txt >> data2.txt; done 

the array seems fine, works when replace gawk command echo command. i've tried replace $i "$i", ${i}, "${i}", etc, didn't help.

any idea i'm doing wrong?? i'm kinda new linux, sorry in advance noob question!

the correct way this:

for in "${array[@]}"   awk '$1 == i' i="$i" data1.txt done > data2.txt 

if want avoid creating awk variable can this, not advise because changes scope of variable:

export in "${array[@]}"   awk '$1 == environ["i"]' data1.txt done > data2.txt 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -