<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[BOL: Perl script to extract lines with matching ids !!]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/27955/perl-script-to-extract-lines-with-matching-ids?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/27955/perl-script-to-extract-lines-with-matching-ids?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/27955/perl-script-to-extract-lines-with-matching-ids</guid>
	<pubDate>Tue, 21 Jun 2016 09:24:46 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/27955/perl-script-to-extract-lines-with-matching-ids</link>
	<title><![CDATA[Perl script to extract lines with matching ids !!]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl
use strict;
use warnings;
my %patterns;

#USAGE: perl extactByIds.pl Idsfile1 file2 &gt; Result

# Open file and get patterns to search for
open(my $fh2,&quot;&lt;&quot;,&quot;$ARGV[0]&quot;)|| die &quot;ERROR: Could not open file2&quot;;
while (&lt;$fh2&gt;)
{
   chop;
   $patterns{$_}=1;
}

# Now read data file
open(my $fh1,&quot;&lt;&quot;,&quot;$ARGV[1]&quot;)|| die &quot;ERROR: Could not open file1&quot;;
while (&lt;$fh1&gt;)
{
   # You might need to adjust this place according to your file type
   #(undef,$srch,undef)=split;
   my @ids=split (/\t/, $_);
   print $_ if defined $patterns{$ids[0]};
}</code>]]></description>
	<dc:creator>Surabhi Chaudhary</dc:creator>
</item>

</channel>
</rss>