Sponsored Content
Full Discussion: lookup in a list
Top Forums Shell Programming and Scripting lookup in a list Post 302260474 by migurus on Thursday 20th of November 2008 03:54:57 PM
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?
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
newinv(1)						      General Commands Manual							 newinv(1)

NAME
newinv - Updates distribution kit master inventory SYNOPSIS
/usr/bin/newinv mi-file input-path... OPERANDS
The pathname of the master inventory file to be processed. If no master inventory file exists, you must create an empty one before using the newinv command. The name of the product hierarchy to be scanned for files belonging in the inventory. All files and directories found below the input-path are processed as belonging in the inventory. DESCRIPTION
The newinv command interactively maintains the master inventory files used for producing distribution kits in setld format. The program updates the master inventory for a product when changes are made to the hierarchy of files that are to be packaged in the subsets which constitute the product. The product hierarchy is scanned to produce a list of component path names relative to input-path. The list of pathnames is processed against the mi-file to produce a list of files that have been removed from the product hierarchy and a list of files that have been added. The user is then given an opportunity to intervene and direct the inventory maintenance by editing these lists. The user is placed in the editor with each list available for editing. The editor used is the one specified by the EDITOR environment variable. If EDITOR is not set, vi is used. When editing the list of files that have been removed from the product, the user is expected to verify that the removals were intentional and confirm the intent by removing the associated records from the file. When editing the list of added files, the user is expected to provide options and subset information for each new file, transforming the elements of the list into master inventory records. To produce a new copy of the master inventory file, both of these lists are merged with the records for the files which existed in the pre- vious version and are still included. RESTRICTIONS
The default text editor, if not specified in $EDITOR, is /usr/ucb/vi. Files in the product hierarchy cannot be excluded from the master inventory. Files can be blocked from being kitted in the final distribu- tion kit by setting the subset field of the master inventory record to a minus sign (-). ERRORS
The mi-file specified on the command line cannot be found. The input-path directory specified on the command line does not exist. EXAMPLES
To update the hypothetical master inventory file OAT100.mi from the hierarchy beginning at /var/kits/input, type: newinv OAT100.mi /var/kits/input FILES
Backup copy of master inventory The list of files missing from the product The list of files new to the product Intermediate join file List of all files in the product SEE ALSO
invcutter(1), kits(1), vi(1), setld(8) stl_mi(4) environ(5) Guide to Preparing Product Kits newinv(1)
All times are GMT -4. The time now is 03:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy