直接上代码:
#!/bin/bash
for sample in A B C D; do
cd /data/output/${sample}/
# 接下来是重点,使用内联重定向符号<<和首尾标记,将多行文本写入json文件
# 首尾标记可以是任意选择,我这里用EOF(像haha,hehe等也是可以作为标记的),那么两个EOF中间的文本会被重定向至json文件
# 首尾标记中间的文本除了确实需要缩进的地方,不 需 要 额 外 缩 进
# 在文本文件中,也可以调用变量,如${sample}
cat>preprocessing-for-variant-discovery-gatk4.b37.inputs.json<<EOF
{
"PreProcessingForVariantDiscovery_GATK4.sample_name": "${sample}",
"PreProcessingForVariantDiscovery_GATK4.ref_name": "b37",
"PreProcessingForVariantDiscovery_GATK4.flowcell_unmapped_bams_list": "$(pwd)/bamlist.txt",
"PreProcessingForVariantDiscovery_GATK4.unmapped_bam_suffix": ".unmap.bam",
"PreProcessingForVariantDiscovery_GATK4.ref_dict": "/root/gatk-workflows/input/human_g1k_v37_decoy.dict",
"PreProcessingForVariantDiscovery_GATK4.ref_fasta": "/root/gatk-workflows/input/human_g1k_v37_decoy.fasta",
"PreProcessingForVariantDiscovery_GATK4.ref_fasta_index": "/root/gatk-workflows/input/human_g1k_v37_decoy.fasta.fai",
"PreProcessingForVariantDiscovery_GATK4.SamToFastqAndBwaMem.ref_sa": "/root/gatk-workflows/input/human_g1k_v37_decoy.fasta.sa",
"PreProcessingForVariantDiscovery_GATK4.SamToFastqAndBwaMem.ref_amb": "/root/gatk-workflows/input/human_g1k_v37_decoy.fasta.amb",
"PreProcessingForVariantDiscovery_GATK4.SamToFastqAndBwaMem.ref_bwt": "/root/gatk-workflows/input/human_g1k_v37_decoy.fasta.bwt",
"PreProcessingForVariantDiscovery_GATK4.SamToFastqAndBwaMem.ref_ann": "/root/gatk-workflows/input/human_g1k_v37_decoy.fasta.ann",
"PreProcessingForVariantDiscovery_GATK4.SamToFastqAndBwaMem.ref_pac": "/root/gatk-workflows/input/human_g1k_v37_decoy.fasta.pac",
"PreProcessingForVariantDiscovery_GATK4.dbSNP_vcf": "/root/gatk-workflows/input/dbsnp_138.b37.vcf",
"PreProcessingForVariantDiscovery_GATK4.dbSNP_vcf_index": "/root/gatk-workflows/input/dbsnp_138.b37.vcf.idx",
"PreProcessingForVariantDiscovery_GATK4.known_indels_sites_VCFs": [
"/root/gatk-workflows/input/Mills_and_1000G_gold_standard.indels.b37.vcf"
],
"PreProcessingForVariantDiscovery_GATK4.known_indels_sites_indices": [
"/root/gatk-workflows/input/Mills_and_1000G_gold_standard.indels.b37.vcf.idx"
]
}
EOF
done
使用内联重定向符号<<和首尾标记,可以将多行文本写入json文件
首尾标记可以是任意选择,我这里用EOF(像haha,hehe等也是可以作为标记的),那么两个EOF中间的文本会被重定向至json文件
首尾标记中间的文本除了确实需要缩进的地方,不 需 要 额 外 缩 进
在文本文件中,也可以调用变量,如${sample}