1

我正在尝试使用 SED 命令从我的文件中替换/删除 rs 数字。我有一个 VCF 文件:

##reference=file:/hs37d5.fasta

#CHROM  POS     ID      REF     ALT     QUAL    FILTER  INFO    FORMAT  SC_PCHD5235298

1       10234   rs145599635     C       T       153.34  .

我想仅在不以 # 开头的行上替换 rs* 条目,例如,我想用点替换 rs145599635。并希望它忽略以 # 开头的行的标题。

我试过了

sed "/^[^#]/s/rs.*/./g" test.vcf

但它会删除 rs 之后的所有内容。

4

1 回答 1

3

You can try with this,

Ex:

  sed -i 's/\(^[^#].*\)rs[0-9]\+\( .*\)/\1rs.\2/' test.vcf

I altered your command.You have to write like this.

   sed -i "/^[^#]/s/rs[0-9]\+/rs./g" test.vcf

My test.vcf file looks like this.I think your file looks like this only.

  ##reference=file:/hs37d5.fasta

  #rs145599635 C T 153.34 .
  #1 10234  rs145599635 C T 153.34  .
  #CHROM POS ID REF ALT QUAL FILTER INFO FORMAT SC_PCHD5235298

  1 10234  rs145599635 C T 153.34  .

I hope this will help you.

于 2012-05-10T12:05:30.553 回答