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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

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

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 12-10-2003
gillbates gillbates is offline
Registered User
  
 

Join Date: Mar 2002
Location: DC
Posts: 46
file lookup

I need to do a text lookup for multiple records against a file that contains a key and two results. I found this code:

str=`awk '$1 == search' search=$1 lkup.tbl

It's a little tricky because the first $1 is the key variables location in the lkup.tbl and the second $1 is the parameter passed to the shell.

This works fine if I call it from a shell passing it a key. However I need to do this for thousands of records at a time and can't figure out how to get it to work inside of a awk function.

Any suggestions on how to do this lookup? I searched the site and couldn't find any prior entries on lookups. Thanks, Gill
  #2 (permalink)  
Old 12-10-2003
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
can you provide us a snipit of data to work with, and an example of how you want it to be displayed on screen?
  #3 (permalink)  
Old 12-10-2003
gillbates gillbates is offline
Registered User
  
 

Join Date: Mar 2002
Location: DC
Posts: 46
01077011300 1.2556 0.9865

The 11 byte variable is a location code. They come from the census. I can run my data through an address scrubber and get this information. Then I need to perform the lookup on the data above to get the two percents and add them to my record. I don't need to display anything on my screen. Gill
  #4 (permalink)  
Old 12-10-2003
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
Things i am assumeing:

1) you have a text file in the format:
KEY Var1 Var2
01077011300 1.2556 0.9865

2) after you get this information (for a specific client you request) you want to update a DB of somesort?


The portion of your question i am not understanding is:
"Then I need to perform the lookup on the data above to get the two percents and add them to my record. "

What kind of record are you updateing? Where do you want this data to go? what format is the "record" in? is it also in the same format as the data file?

with the code below it just prints it to STDOUT. you can easily redirect it to a file or insert it into a db.

Code:
#!/usr/bin/perl -w
#KEY Var1 Var2
#01077011300 1.2556 0.9865
#
# to use the program ./test.plx <filename> <client code you want to search for in file>

use strict;

my ($filename, $cli_code)=@ARGV;
open (FILE,"$filename") or die "Cant open file ($!)\n";

foreach (<FILE>) {
        if (/^$cli_code/) {
                chomp;
                my ($key, $var1, $var2) = split();
                print "Key: $key Var1: $var1 Var2: $var2\n";
        }
}

[qgatu003]$./test.plx datafile 01077011300
Key: 01077011300 Var1: 1.2556 Var2: 0.9865
Key: 01077011300 Var1: .2556 Var2: 10.9865
[qgatu003]$cat datafile
01077011300 1.2556 0.9865
01077011301 1.234 23.3432
01077011300 .2556 10.9865

Last edited by Optimus_P; 12-10-2003 at 06:15 PM..
  #5 (permalink)  
Old 12-10-2003
gillbates gillbates is offline
Registered User
  
 

Join Date: Mar 2002
Location: DC
Posts: 46
Thanks for your reply, I should have written that better. What's happening is I'm running a bourne shell script that sends data and a trigger file to another system that runs my data through an outside vendors system. That system use to return both the key and the two percentages. In the future it will only return the key but they supplied the text file above so I would be able to generate those two percentages by performing a lookup on the key or first field.

I'm manipulating that data in an awk script when I get it back and I was hoping to be able to do the lookup inside of the awk script although I can do it separately if needed.

My problem is the awk command above does exactly what I want it too but I can't figure out how to make it work inside an awk script with a variable. I sort my returned file into a pipe into the awk script.

So to summarize I need to take a file that has many records and add the two percentages to each record based on the location code. Once the data is in the correct format I just move the file to a particular location and a java app takes over and sticks it in sybase.

Thanks, Greg
  #6 (permalink)  
Old 12-10-2003
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
ok i think i see what your trying to do now.

sorry but i only use the most basic forms of awk. hopefully someone else can give you a hand.

if you want to investigate a completely perl route we can prolly pound something out.

i suppose we would need:
1) test data (you supplied that above)
2) list the ways your minipulateing the data
3) show the format you want the data in the file you pass to the java app.

var1=1
var2=2
just a question. are you adding var1+var2?

so it looks like:
location_code1 3
location_code2 5
....
  #7 (permalink)  
Old 12-12-2003
gillbates gillbates is offline
Registered User
  
 

Join Date: Mar 2002
Location: DC
Posts: 46
I ran out of time and the process goes through a sas step right after this so I just fixed the variables there. It's real easy to do lookups in sas.

To answer you question no I don't add the variables together I just need to pass them on and financial people make decisions based on them.

If anyone out there knows how I could have implemented this in awk I'd still like to know.

Thanks, Gill
Sponsored Links
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 03:30 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