【问题标题】:How to extract filename without extension and change header in the same file with the extracted name?如何提取没有扩展名的文件名并使用提取的名称更改同一文件中的标题?
【发布时间】:2019-02-27 06:40:43
【问题描述】:

我有大约 30 个文件名为 ID_001.new.vcf 的 VCF 文件。我只想从文件名中提取“ID_001”部分,并在给出“Sample1”的 VCF 文件的标题行中更改它:

#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT Sample1

所以结果看起来像:

#CHROM  POS     ID      REF     ALT     QUAL    FILTER  INFO    FORMAT  ID_001

我该怎么做?

我尝试在 bash 中使用 echo 并从文件名中提取 ID,但我无法对其进行迭代以在文件内进行更改。

感谢您的帮助。

【问题讨论】:

    标签: linux bash vcf-variant-call-format


    【解决方案1】:

    您可以使用以下内容:

    for file in *.vcf 
    do 
       name=$(basename -- "$file" .new.vcf) 
       sed -i "s/Sample1/$name/g" "$file" 
    done
    

    【讨论】:

      猜你喜欢
      • 2016-07-05
      • 1970-01-01
      • 2021-09-19
      • 2018-10-27
      • 2015-10-03
      • 2012-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多