This is a quick and dirty method (I doubt its efficiency for data of your size):
( Assuming the file name containing nos is acct_nos, wherein the acct numbers are vertically placed, like this:
acct_nos:
123
456
I am assuming the file name of the file containing acct information as "acct_info")
The following statements should work ( these rely on certain special characters...again assuming that you your data does not use characters "#" AND "@". In case if they do replace these by characters not being used)
sed 's/^/ACCOUNT NO |/g' acct_nos|sed 's/$/@/g' >temp_nos
sed 's/PAGESTART/#PAGESTART/g' acct_info|tr '\n' '@'|tr '#' '\n'>temp_info
grep -f temp_nos temp_info|tr '@' '\n'
Heres another way with PERL. This should IDEALLY be faster(and better--- it takes care a lot of whitespace worries. For ex if the acct_nos file lists nos as:
123
456
it wouldnt be affected. Also the script works irrespective of whether the ACCOUNT NO line has some no. of whitespaces at the start or before the "pipe" (or tag as u might say) delimiter (though it is assumed that "ACCOUNT" and "NO" are separated by one space only). Same goes for the account no.):
find_acct.pl:
#!/usr/bin/perl
open (ACCT_INFO,"acct_info");
open (ACCT_NOS,"acct_nos");
@acct_nos=<ACCT_NOS>;
close (ACCT_NOS);
$acct_present="no";
while(<ACCT_INFO>)
{
chop($_);
@buffer;
@chk_pagestart_or_acct=split(/\|/);
if($chk_pagestart_or_acct[0] =~ /^\s*PAGESTART\s*$/)
{ if($acct_present eq "no")
{splice(@buffer,0,@buffer);}
else
{ print ("@buffer");
splice(@buffer,0,@buffer);
}
}
else {
if($chk_pagestart_or_acct[0] =~ /^\sACCOUNT NO\s$/)
{
$chk_pagestart_or_acct[1]=~ s/^\s+//;
$chk_pagestart_or_acct[1]=~ s/\s+$//;
@found=grep(/^\s*$chk_pagestart_or_acct[1]\s*$/,@acct_nos);
$acct_present=($#found == -1 ? "no" : "yes");
splice\(@found,0,@found\);
\}
}
push(@buffer,$_."\n");
}
if($acct_present eq "yes")
{ print("@buffer");}
close (ACCT_INFO);