Awk Iterate through several Arrays in a for loop -


i have created awk program go through columns of file , count each distinct word , output totals separate files

awk -f"$delim" {field_arr1[$1]++; field_arr2[$2]++; field_arr3[$3]++; field_arr4[$4]++};  end{\     #  output fields     out_field1="top_field1"     out_field2="top_field2"     out_field3="top_field3"     out_field4="top_field4"      for( i=1; <= nf; i++)     {         (element in field_arr$i)          {             print element"\t"field_arr$i[element] >>out_field$i;         }     } }' inputfile 

but don't know appropriate syntax, loop iterate through field_arr1, field_arr2, field_arr3, field_arr4?

i have tried using: i, $i, ${i}, {i}, "$i", , "i".

am trying wrong approach or there way change field_arr$i field_arr1..4?

thanks advice.

awk variables don't work way; you'll have them individually name, or use fake multidimensional arrays , parse out components, along lines of:

{field_arr[1, $1]++; field_arr[2, $2]++; field_arr[3, $3]++; field_arr[4, $4]++} end {   (elt in field_arr) {     split(elt, ec, subsep)     print ec[2] "\t" field_arr[elt] >> ("top_field" ec[1])   } } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -