• 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!"
    
  • 相关阅读:
    linux地址空间
    装饰器模式
    图像分类(四) 全面解读复现GoogleNet_InceptionV1-V4
    LTpowerCAD II和LTpowerPlanner III
    E : A DS顺序表_删除有序表中的重复元素
    QT基础教程(文本绘制)
    深入分析APK文件格式
    技术管理者的管理框架
    【软考】模块之间的耦合性及其代码示例
    Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间
  • 原文地址:https://blog.csdn.net/Hodors/article/details/126168075