Bash Scripting

Associate
Joined
6 Nov 2006
Posts
722
Location
Devon
I'm after a little help with looping in bash. I have a script which at the moment looks like

Code:
cut -f 3- chunk2-EUGENE2_chr2.imputed.dose > 2temp2.txt &
cut -f 3- chunk3-EUGENE2_chr2.imputed.dose > 2temp3.txt &
cut -f 3- chunk4-EUGENE2_chr2.imputed.dose > 2temp4.txt &
cut -f 3- chunk5-EUGENE2_chr2.imputed.dose > 2temp5.txt &
cut -f 3- chunk6-EUGENE2_chr2.imputed.dose > 2temp6.txt &
cut -f 3- chunk7-EUGENE2_chr2.imputed.dose > 2temp7.txt &
cut -f 3- chunk8-EUGENE2_chr2.imputed.dose > 2temp8.txt &
cut -f 3- chunk9-EUGENE2_chr2.imputed.dose > 2temp9.txt &
cut -f 3- chunk10-EUGENE2_chr2.imputed.dose > 2temp10.txt &
cut -f 3- chunk11-EUGENE2_chr2.imputed.dose > 2temp11.txt &
cut -f 3- chunk12-EUGENE2_chr2.imputed.dose > 2temp12.txt &
cut -f 3- chunk13-EUGENE2_chr2.imputed.dose > 2temp13.txt &
cut -f 3- chunk14-EUGENE2_chr2.imputed.dose > 2temp14.txt &
cut -f 3- chunk15-EUGENE2_chr2.imputed.dose > 2temp15.txt &
cut -f 3- chunk16-EUGENE2_chr2.imputed.dose > 2temp16.txt &
cut -f 3- chunk17-EUGENE2_chr2.imputed.dose > 2temp17.txt &

wait

paste chunk1-EUGENE2_chr2.imputed.dose 2temp2.txt 2temp3.txt 2temp4.txt 2temp5.txt 2temp6.txt 2temp7.txt 2temp8.txt 2temp9.txt 2temp10.txt 2temp11.txt 2temp12.txt 2temp13.txt 2temp14.txt 2temp15.txt 2temp16.txt 2temp17.txt > EUGENE2_chr2.imputed.dose &

cp chunk1-EUGENE2_chr2.imputed.info EUGENE2_chr2.imputed.info
tail -n +2 chunk2-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk3-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk4-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk5-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk6-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk7-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk8-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk9-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk10-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk11-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk12-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk13-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk14-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk15-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk16-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info
tail -n +2 chunk17-EUGENE2_chr2.imputed.info >> EUGENE2_chr2.imputed.info

Now the number of chunk files varies with each chr from 1 to 22 and I'm wanting to write one script to loop through all of them and merge them in the same way as above. I know that if I didn't need to treat the first one differently I could do

Code:
for chunk in chunk*info
do
...
done

but is there a way to make it loop and treat the first chunk differently?

Thanks
 
Associate
OP
Joined
6 Nov 2006
Posts
722
Location
Devon
Thanks, I hadn't thought of doing that. I think that would work for the cut and the concatenate loops, but is there a way I can do the paste command as I want to paste the same number of files as there are chunks? (I guess I could just hard code a number of files higher than the number of chunks I'll encounter but it seems like there must be a better way of doing it)
 
Back
Top Bottom