Last active
August 29, 2015 14:04
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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