The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
file Lookup using awk jerome Sukumar Shell Programming and Scripting 1 08-30-2007 03:28 AM
getting particular text after grep from lookup file napolayan UNIX for Dummies Questions & Answers 10 10-20-2006 10:52 AM
Lookup with a file pavan_test UNIX for Dummies Questions & Answers 5 07-21-2006 10:57 AM
reverse lookup file problem Westy564 IP Networking 2 01-09-2004 02:55 PM
file lookup gillbates UNIX for Dummies Questions & Answers 6 12-12-2003 02:04 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-28-2008
ukatru ukatru is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 38
Lookup on a file

Hi,

I have the following requirement.

I have one lookup file which contains 15 columns and 7000 records.

Ex:

123,MEDICA,134,145,1178,123,678,345,2345,HP,COL,K12,SR,OX,78919

I have input file which contains 14 columns and 20 million records.Some times the record count is more than 20 million.

I need to match the first 14 columns with 14 columns in the lookup file and if matches i need the 15 the column.

Can any one please help me and give me some code which will process very effeciently.
I need to finish this process less than 20 minutes.

Can any one please suggest me how can we acheive this using ksh or even perl script is also good.

Thanks
  #2 (permalink)  
Old 07-30-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
Post

Code:
#!/usr/bin/perl -w
$lookupfile=$ARGV[0];
open(LOOKUP,"<$lookupfile") || die "Argh: $lookupfile : $!";
while (<LOOKUP>) {
    if (/(.*)\,([^\,])$/) {
        $lookup{$1}=$2;
    }
}
close (LOOKUP);

while(<STDIN>) {
    $key=$_;
    chomp $key;
    if ($match=$lookup{$key}) {
        print "${key},${match}\n";
    } else {
        print "${key},ERROR!\n";
    }
}
Usage: scriptname.pl lookupfile.txt < inputfile.txt
  #3 (permalink)  
Old 07-31-2008
ukatru ukatru is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 38
Thanks for your reply.And there is small change in the requirement.
Lookupfile

123,MED,134,145,(117-200),<ANY>,678,345,234,HP,CO,K12,SR,OX,7891

InPutFile

123,MEDICA,134,145,118,123,678,345,2345,HP,COL,K12,SR,OX

Here column highlited in red in the input text file which falls in between 117-200(range comparision) and column highlighted in rose colour in the input file equals <ANY> in the lookupfile.Can you please tell me how to acheive this by using the above code.
  #4 (permalink)  
Old 07-31-2008
ukatru ukatru is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 38
I used the above script and i am getting the following output

#!/usr/bin/perl -w
$lookupfile=$ARGV[0];
open(LOOKUP,"<$lookupfile") || die "Argh: $lookupfile : $!";
while (<LOOKUP>) {
if (/(.*)\,([^\,])$/) {
$lookup{$1}=$2;
}
}
close (LOOKUP);
while(<STDIN>) {
$key=$_;
chomp $key;
if ($match=$lookup{$key}) {
print "${key},${match}\n";
} else {
print "${key},ERROR!\n";
}
}


scripname.pl lkpfile.txt < inputfile.txt
123,123,123,123,123,123,123,123,123,123,123,123,123,123,ERROR!
cat lkpfile.txt
123,123,123,123,123,123,123,123,123,123,123,123,123,123,uma
cat inputfile.txt
123,123,123,123,123,123,123,123,123,123,123,123,123,123
  #5 (permalink)  
Old 07-31-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
I think you've got those files the wrong way around. I would expect inputfile.txt to be the input data (i.e. with "uma") and lkpfile.txt to be the keys you are looking up.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0