Please tell me why this program is not working?? help me improve it.
for i in $(seq 2 30); do awk '{if ($i < 0.05) print $1,$i}' test.txt > phen_$i.txt; done
File test.txt looks like following:
name phen1 phen2
rs549 0.02 0.02
rs699 0.03 0.03
rs701 1 1
rs751 0.449 0.449
rs884 1 1
rs923 0.9775 0.02
rs970 0.9836 0.03
rs1085 0.0001 0.99
rs1220 0.9316 0.9316
output file are expected to be two different files namely phen_2.txt and phen_3.txt containing col1 and col2, and col1 and col3 respectively according to if condition.
expected outcome for phen_2.txt:
rs549 0.02
rs699 0.03
rs1085 0.0001
expected outcome for phen_3.txt:
rs549 0.02
rs699 0.03
rs923 0.02
rs970 0.03
please help!
Use variable passing (
-v) to get the shell variable into the AWK script.You don’t need
seq.Edit:
Fixed some overzealous and bad errors on my part.
Here’s how you can do the same thing completely within AWK:
This only goes through the input file once, but it cycles through the set of output files for each line of input. The shell version reads the input file repeatedly, but writes to each output file once.