Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Script linux loop for multiple number

I have a list of Linux commands that I need to repeat up to 670. How can I automate the commands, so I don’t have to do the 670 times. I don’t know how to do all the operations from C1, C2, C3 …. to C670?

#START C1


mkdir C1

cd C1

awk '/Prymnesium_parvum_GenomeV1.0_Contig_1\t/' ../Methy_670.txt | cut -f 2 > IllU_C1.txt

awk '/Prymnesium_parvum_GenomeV1.0_Contig_1\t/' ../TE/TEannotation_Prymnesium_parvum_GenomeV1.0.gff3 | cut -f 4,5 > TE_C1.txt

paste TE_C1.txt IllU_C1.txt> C1.txt


awk -f ../com.awk C1.txt C1.txt > res_C1

wc -l res_C1

wc -l TE_C1.txt

cd ..

###Stop C1

#Start C2

mkdir C2

cd C2

awk '/Prymnesium_parvum_GenomeV1.0_Contig_2\t/' ../Methy_670.txt | cut -f 2 > IllU_C1.txt

awk '/Prymnesium_parvum_GenomeV1.0_Contig_2\t/' ../TE/TEannotation_Prymnesium_parvum_GenomeV1.0.gff3 | cut -f 4,5 > TE_C1.txt

....

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Not tested:

#!/bin/bash

for C in {1..670};do
echo START ${C}

mkdir -p ${C} && cd ${C}

awk '/Prymnesium_parvum_GenomeV1.0_Contig_'${C}'\t/' ../Methy_670.txt | cut -f 2 > IllU_${C}.txt

awk '/Prymnesium_parvum_GenomeV1.0_Contig_'${C}'\t/' ../TE/TEannotation_Prymnesium_parvum_GenomeV1.0.gff3 | cut -f 4,5 > TE_${C}.txt

paste TE_${C}.txt IllU_${C}.txt> ${C}.txt

awk -f ../com.awk ${C}.txt ${C}.txt > res_${C}

wc -l res_${C}

wc -l TE_${C}.txt

cd ..

echo Stop ${C}

done

I am not sure what awk '/Prymnesium_parvum_GenomeV1.0_Contig_1\t/' ../Methy_670.txt does but you will have to figure out how you can add ${C} in there as single quotes will not parse ${C}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading