linux - Directing awk output to variable -



linux - Directing awk output to variable -

new guy here problem have easy solution, can't seem manage.

so, have big list of files need process using same command line program, , i'm trying write little shell script automate this. wrote read input file name text file, , repeat command each of files. far good. problem though naming output. each file named in general format "lane_number_bla_bla_bla", , processed in pairs. so, there "lane_1_bla_bla_bla_001" , "lane_1_bla_bla_bla_002" need combine single output file. this, i'm trying utilize awk read sample number .txt list of input files , parse output file number. here's code came (note echo statement before command there testing; it's removed when comes run actual program; not actual command rather more complicated, principle still applies):

echo "which input1 should use?" read text input1=$text echo "which input2 should use?" read text input2=$text echo "how many lines?" read text n=$text in $(seq 1 $n) awkinput1=$(awk nr==$i $input1) awkinput2=$(awk nr==$i $input2) num=$(awk 'nr==$i{print $2 }' fs="_" $input1) lane=$(awk 'nr==$i{print $1 }' fs="_" $input1) echo "command $awkinput1.in > $awkinput1.out && command $awkinput2.in > $awkinput2.out && command cat $awkinput1.out $awkinput2.in > $num-$lane-cat.out &" if (( $i % 10 == 0 )); wait; fi # limit 10 concurrent subshells. done

when run this, both $awkinput fields replaced in comand line appropriate filename, not $num , $lane fields, print nothing.

so, doing wrong? i'm sure it's pretty simple, tried quite lot of different ways format relevant awk command, , nil seems work. i'm doing on remote linux server using ssh protocol, if makes difference.

thanks lot!

shell not parse $i quoted single quote ('). quoted string should terminated before $i. fs should set before parsing lines.

following code work.

num=$(awk 'begin{fs="_"} nr=='$i'{print $2 }' $input1) lane=$(awk 'begin{fs="_"} nr=='$i'{print $1 }' $input1)

code below more efficient:

while read in1 ; read in2 <&3 num=$(awk 'begin{fs="_"} {print $2 }' <<<"$in1") lane=$(awk 'begin{fs="_"} {print $1 }' <<<"$in1") ... done <$input1 3<$input2

linux

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -