Skip to content

Instantly share code, notes, and snippets.

@davfre
Last active August 29, 2015 14:04
Show Gist options
  • Save davfre/a3689815c79f17655e05 to your computer and use it in GitHub Desktop.
Save davfre/a3689815c79f17655e05 to your computer and use it in GitHub Desktop.
Filter a textfile to output only the lines where a given identifier is present.
#!/usr/bin/perl
use strict;
my $usage = "cat input.gtf | $! idlist.txt > filtered.gtf\n";
my %ids;
my $FN_idlist = $ARGV[0];
open my $FH_idlist, "<", $FN_idlist or die $usage;
# read id list to memory
while(my $id = <$FH_idlist>){
chomp $id;
$ids{$id} = 1;
}
while(my $line = <STDIN>){
my ($xloc_id) = $line =~ /(XLOC_\d+)/;
if(defined($ids{$xloc_id})){
print $line;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment