多个数字的脚本 linux 循环
Script linux loop for multiple number
我有一个 Linux 命令的列表,我需要重复最多 670 次。我怎样才能使命令自动化,这样我就不必重复 670 次。从C1,C2,C3....到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
....
未测试:
#!/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
我不确定 awk '/Prymnesium_parvum_GenomeV1.0_Contig_1\t/' ../Methy_670.txt
的作用,但您必须弄清楚如何在其中添加 ${C},因为单引号不会解析 ${C}
另一个观点:awk 可以做 cut 做的事
#!/usr/bin/env bash
prep_dir() {
local n=
local c=C$n ill=IllU_$c.txt te=TE_$c.txt
local pattern="Prymnesium_parvum_GenomeV1.0_Contig_${n}\t"
if mkdir "$c" && cd "$c"; then
awk -v p="$pattern" '[=10=] ~ p {print }' ../Methy_670.txt > "$ill"
awk -v p="$pattern" '[=10=] ~ p {print , }' ../TE/TEannotation_Prymnesium_parvum_GenomeV1.0.gff3 > "$te"
paste "$te" "$ill" > "$c.txt"
awk -f ../com.awk "$c.txt" "$c.txt" > "res_$c"
wc -l "res_$c"
wc -l "$te"
cd ..
fi
}
for i in {1..670}; do
prep_dir $i
done
我有一个 Linux 命令的列表,我需要重复最多 670 次。我怎样才能使命令自动化,这样我就不必重复 670 次。从C1,C2,C3....到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
....
未测试:
#!/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
我不确定 awk '/Prymnesium_parvum_GenomeV1.0_Contig_1\t/' ../Methy_670.txt
的作用,但您必须弄清楚如何在其中添加 ${C},因为单引号不会解析 ${C}
另一个观点:awk 可以做 cut 做的事
#!/usr/bin/env bash
prep_dir() {
local n=
local c=C$n ill=IllU_$c.txt te=TE_$c.txt
local pattern="Prymnesium_parvum_GenomeV1.0_Contig_${n}\t"
if mkdir "$c" && cd "$c"; then
awk -v p="$pattern" '[=10=] ~ p {print }' ../Methy_670.txt > "$ill"
awk -v p="$pattern" '[=10=] ~ p {print , }' ../TE/TEannotation_Prymnesium_parvum_GenomeV1.0.gff3 > "$te"
paste "$te" "$ill" > "$c.txt"
awk -f ../com.awk "$c.txt" "$c.txt" > "res_$c"
wc -l "res_$c"
wc -l "$te"
cd ..
fi
}
for i in {1..670}; do
prep_dir $i
done