for loop - awk increment the input field while looping -
i have loop on array. looking on $11 field. however, want check different field every time.
- when
i
first element, want @$11
field. - when
i
second element, want @$12
field. - when
i
third, want @$13
field.
i using:
for in "${array[@]}" awk -v ofs="\t" -v str1="$i" -v thr="$thr" '{ if($11>=thr) print "chr" $1, $2 ,$3 , str1 ;}' comb.txt > $i".bed" done
how can this?
my variables follows:
str1="cd45ra+_naive" str2="cd45ro+_mem" str3="cd127-_treg" str4="il17-_th_stim_macs" str5="il17+_th17_stim" array=($str1 $str2 $str3 $str4 $str5) thr=10
given array names
, can loop through values , know index doing:
for ((i=0; i<${#names[@]}; i++)) echo "$i, ${names[$i]}" done
for example,
$ names=('a' 'b' 'c') $ ((i=0; i<${#names[@]}; i++)); echo "$i, ${names[$i]}"; done 0, 1, b 2, c
based on logic, in case can say:
for ((i=0; i<${#array[@]}; i++)) awk -v index="$i" -v str1="${names[$i]}" -v thr=$thr '{ if($(index+11)=>thr) ... }' comb.txt ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ done
that is, providing index $i index
awk , value ${names[$i]}
str
. then, within awk code can play around index value, saying index + 10
or whatever need number.
Comments
Post a Comment