lookup in a list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting lookup in a list
# 1  
Old 11-20-2008
lookup in a list

I have a list of ids and a master list. I need to display entries from the master list matching ids in the first list. The master list is space delimited, id is 1st field.

$ cat id_list
2010
7
51

$ cat master_list
1 one detail1 detail2
2 two detail1 avg1 detail2 avg2
... etc ...

There are not more than 1000 entries in master_list and around 100 entries in id_list.

My code:
Code:
 
for id in $( cat id_list ); do 
awk -e'{ if($1 == xid){print}}' -v xid=$id master_list
done

results:
2010 two thousand and ten detail1 detail2 avg1 avg2
7 seven detail1 detail2
51 fifty one avg-step-1 avg-step-2

It works, but I suspect ther are much better solutions without calling awk in the loop. Any ideas?
# 2  
Old 11-21-2008
Computer

How about this ?

Code:
cat id_list | while read line ; do grep $line master_list ; done

CMIIW, YMMV

HTH Smilie
# 3  
Old 11-21-2008
No, grep would not work, as i need exact match of id field.
To clarify, imagine that my id_list has id = 1, then all lines in master list having '1' anywher within them would be selected.
# 4  
Old 11-24-2008
If the id_list and master_list have the field = 1 at the beggining of the line (always first field of each line).
the script should be :

Code:
cat id_list | while read line ; do grep ^$line master_list ; done

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Whois Lookup

Hi. I've just made our internal Whois lookup service available for all forum users, not only moderators and admins. Whois Database It's basically the same whois info you can get from your command line and many other web sites. If you would like to see other features, please post in... (0 Replies)
Discussion started by: Neo
0 Replies

2. Shell Programming and Scripting

lookup script

dear all.. need your help.. i have searching but still didn't find what i need. i have 2 file, i want to lookup one to many, the key is $1 : main.txt code.txt output.txt thanks.. br, herman (2 Replies)
Discussion started by: buncit8
2 Replies

3. Shell Programming and Scripting

lookup

I have a lookup file in unix say /data/lkp.dat (First line is header and space delimited) and the content is shown below. Another file which contains the job_name and rec_count lets say /data/data_file.dat(no header pipe delimited file). Now i want to do a lookup on job_name and my output should... (3 Replies)
Discussion started by: dr46014
3 Replies

4. Shell Programming and Scripting

List of IPs & database lookup

I am trying to feed a list of IP's to do lookups from a database. My script works only for the first IP but all subsequent IPs output as 'unknown'. #!/usr/bin/php -q <? $ip = file('ip.txt'); foreach ($ip as $ip_num => $ip) { echo $ip; $out=sprintf("%u", ip2long($ip)); ... (1 Reply)
Discussion started by: hazno
1 Replies

5. Shell Programming and Scripting

Reverse lookup

hey guys, can anybody help me out here on the following: grep '^\{1,3\}\.\{1,3\}\.\{1,3\}\.\{1,3\}$' ravi.txt mary.txt lisa.txt https://www.unix.com/images/misc/progress.gif i.e what i did was found ip addreses from different files and then i want... (1 Reply)
Discussion started by: ravis83
1 Replies

6. UNIX for Advanced & Expert Users

Clueless about how to lookup and reverse lookup IP addresses under a file!!.pls help

Write a quick shell snippet to find all of the IPV4 IP addresses in any and all of the files under /var/lib/output/*, ignoring whatever else may be in those files. Perform a reverse lookup on each, and format the output neatly, like "IP=192.168.0.1, ... (0 Replies)
Discussion started by: choco4202002
0 Replies

7. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: ukatru
4 Replies

8. Shell Programming and Scripting

lookup script

hello I am a student taking an intro to UNIX class. I have an assignment I am having trouble completing. The assignment is as follows. i have a file called .addr_book that has various names and phone numbers in it. I need to write a script called lookup that will run like this I... (2 Replies)
Discussion started by: tampaJim
2 Replies

9. UNIX for Dummies Questions & Answers

HELP with using a lookup table

Using AIX 5.2, Bourne and Korn Shell. I have two flat text files. One is a main file and one is a lookup table that contains a number of letter codes and membership numbers as follows: 316707965EGM01 315672908ANM92 Whenever one of these records from the lookup appears in the main file... (6 Replies)
Discussion started by: Dolph
6 Replies

10. UNIX for Dummies Questions & Answers

Lookup with a file

Hi All, i have a variable which has a value in it. RETAILER='JEWL' i have a text file. Name: file.txt file.txt ________ WLG 150 JEWL 60 CVS 240 FLN 120 WND 120 I am trying to write a korn script.the script, based on the value in the RETAILER will do a look up against the... (5 Replies)
Discussion started by: pavan_test
5 Replies
Login or Register to Ask a Question