bash语句替换文本,解析json linux文本处理,解析json,替换txt里的字符串,正则表达式
bash语句替换文本,解析json
#!/bin/bash # 这个脚本的目的是, # 拿到输入的json文件; # 解析json文件; # 然后保证 Docker镜像顺利执行; pwdPath=$0 echo "Hello! $pwdPath script is running..." echo "###################################################################" echo "This script is written by (If you have any problems. Please contact @@.com)" jsonfilePath=$1 #用户输入的json路径 # 如果没有前端输入的json文件 则宣布退出 if [ ! "$1" ]; then echo "Usage: bash run_job.sh /Output/*.json|/Output/*.yaml /Input/[H5AD]" exit else echo "input json filename is $jsonfilePath" species=`cat $jsonfilePath | jq -r '.species'` if test $species = "human" then indexDirPath="/ssd1//PBMC_human/star" gtfFilePath="/ssd1//PBMC_human/genes.gtf" elif test $species = "monkey" then indexDirPath="/ssd1//PBMC_monkey/star" gtfFilePath="/ssd1//PBMC_monkey/genes.gtf" elif test $species = "rat" then indexDirPath="/ssd1//PBMC_rat/star" gtfFilePath="/ssd1//PBMC_rat/genes.gtf" else echo "species error" fi fastq1FilePath=`cat $jsonfilePath | jq -r '.fastq1'` fastq2FilePath=`cat $jsonfilePath | jq -r '.fastq2'` CellNum=`cat $jsonfilePath | jq -r '.CellNum'` echo "index dir path is $indexDirPath" echo "gtf file path is $gtfFilePath" echo "fastq1 file path is $fastq1FilePath" echo "fastq2 file path is $fastq2FilePath" echo "CellNum is $CellNum" #接下来是修改runScSpark.sh 并执行 runScSparkFilename="runScSpark.sh" indexOld=$(grep -oP '(?<=-genomeDir\s).*(?=\s\\)' $runScSparkFilename) sed -i "s|$indexOld|$indexDirPath|g" $runScSparkFilename gtfOld=$(grep -oP '(?<=-gtf\s).*(?=\s\\)' $runScSparkFilename) sed -i "s|$gtfOld|$gtfFilePath|g" $runScSparkFilename fq1Old=$(grep -oP '(?<=-fq1\s).*(?=\s\\)' $runScSparkFilename) sed -i "s|$fq1Old|$fastq1FilePath|g" $runScSparkFilename fq2Old=$(grep -oP '(?<=-fq2\s).*(?=\s\\)' $runScSparkFilename) sed -i "s|$fq2Old|$fastq2FilePath|g" $runScSparkFilename cellNumOld=$(grep -oP '(?<=-cellNumber\s).*(?=\s\\)' $runScSparkFilename) sed -i "s|$cellNumOld|$CellNum|g" $runScSparkFilename #bash runScSpark.sh fi echo "###################################################################" echo "Finished!"