This is quite incomplete a specification. Your "Given" is in a file? You want to parse multiple input files named "chrn_GEN2bim" where n comes from your "Given" file? Is the first column of those input files always identical to n?
Thanks for your reply. Sorry I wasnt very clear.
Yes the "Given" is in a file.I want to parse multiple input files named "chr{n}_GEN2bim" where n comes from the first column of my "Given" file.
This could probably be optimized a lot if I knew what you were doing. Whenever you do awk | awk | kitchen | sink, you should replace it with one awk and be done with it.
while read A B C D E
do
awk '$4>(B-500000) && $4<(B+500000)' B="$B" chr${A}_GEN2bim |
awk 'BEGIN {min=1000000000; max=0;}; $4 == "" { next }; $4<min { min = $4; }; $4>max { max=$4; } END {print "chr"$1"\t"min"\t"max}'
done < given > output
Do you want a min/max value for each chrn? Then you need to reset them for every new n.
And, you run your awk script twice for e.g. 1 od 19. So there might not be one single min/max for those as the, say, "tolerances" are different for the two calls.
What I actually want to do is read A and B simultaneously from file 2.
A is the value at the first column, while B is at the second column both from second file
I think it should be like this
while read A B (in this case A is 1 and B is 55518622, so next A is 2 while B is 109815252, and next A is 10 and B=15912165 )
do
awk '$4>(B-500000) && $4<(B+500000)' B="$B" chr${A}_GEN2bim |
awk 'BEGIN {min=1000000000; max=0;}; $4 == "" { next }; $4<min { min = $4; }; $4>max { max=$4; } END {print "chr"$1"\t"min"\t"max}'
done < second_file > output