且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从文件中提取特定数据并将其写入另一个文件

更新时间:2023-01-30 19:29:02

您的数据看起来像是用制表符分隔的.

It looks like your data is tab-separated.

此Perl程序将从第三列中所有具有exon的所有记录中打印第1、4和5列.您需要将open语句中的文件名更改为您的实际文件名.

This Perl program will print columns 1, 4 and 5 from all records that have exon in the third column. You need to change the file name in the open statement to your actual file name.

use strict;
use warnings;

open my $fh, '<', 'genes.gff3' or die $!;

while (<$fh>) {
  chomp;
  my @fields = split /\t/;
  next unless @fields >= 5 and $fields[2] eq 'exon';
  print join("\t", @fields[0,3,4]), "\n";
}

输出

PITG_00002  2 397
PITG_00004  1 1275
PITG_00004  1397  1969