![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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.. |
|
||||
|
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 |
|
||||
|
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 .... |
|
||||
|
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 | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|