lookup in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting lookup in unix
# 1  
Old 05-03-2008
lookup in unix

Hi All
I have got a fixed length file of 80bytes long.The first 4bytes of each record represents a client_number.I need to modify the client number based on another lookup file.
The lookup file contains 2 fields and a comma delimited file.The first line of the lookup file contains the header information.

For example,
The lookup file has a path /data and the name of the file is client_nbr.lkp.The layout of the file is as follows.

From_Nbr,To_Nbr
1212,1100
1425,1233
1520,1400


The path of the original 80byte fixed length file is /temp.This file doesnot contain any header info.

1212.............................<80bytes>
1000.............................<80bytes>
1500.............................<80bytes>
1425.............................<80bytes>
1520.............................<80bytes>

The first 4 digits are client nbr.We have to do a lookup on /data/client_nbr file on From_Nbr field and if it matches the client_nbr will be replaced in the 80byte file with the To_Nbr value.
The final file should be located in /temp and the file name will remain same with only client_nbr info changed for some records where the lookup entry is available.

The final file should look like

1100.............................<80bytes>
1000.............................<80bytes>
1500.............................<80bytes>
1233.............................<80bytes>
1400.............................<80bytes>

Please help me wring a script which will take the 80byte fixed length file as a parameter as this name of the file varies on a daily basis but the content remains the same.
# 2  
Old 05-03-2008
This should give the desired output, you can redirect the output to a new file:

Code:
awk 'BEGIN{FS=","}
{a[$1]=$2}
END {
  while((getline < "/temp/file") > 0 ) {
    if(substr($0,1,4) in a) {
      print a[substr($0,1,4)] substr($0,5)
    }
    else {
      print $0
    }
  }
}' "/data/client_nbr.lkp"

Use nawk or /usr/xpg4/bin/awk on Solaris.

Regards
# 3  
Old 05-03-2008
any suggestions how to do this ???
# 4  
Old 05-03-2008
thanks a lot
# 5  
Old 05-03-2008
i need to pass the input file name as a parameter and get the same file as the output after set operation
# 6  
Old 05-03-2008
A variation on the theme....

nawk -f dr.awk client_nbr.lkp fixedLengthFile

dr.awk:
Code:
awk 'BEGIN{FS=","}
NR==FNR{a[$1]=$2; next}
{
   if (substr($0,1,4) in a)
      print a[substr($0,1,4)] substr($0,5)
   else
      print $0
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Array V-Lookup using UNIX bash

Hey everyone, I am trying to extract column values from a column in a tab-delimited text file and overlay them in a 2nd tab-delimited text file using a V-lookup type script in Unix bash. These are the 1st few rows of the 1st input file IN1: rsid chromosome position allele1 ... (10 Replies)
Discussion started by: Geneanalyst
10 Replies

2. Shell Programming and Scripting

Lookup field values in two fixed format file in UNIX - not working

I have 2 fixed length files input#1 & input#2. I want to match the rows based on the value in position 37-50 in both files (pos 37-50 will have same value in both files). If any matching record is found then cut the value against company code & Invoice number from input file #1 (position 99 until... (3 Replies)
Discussion started by: Lingaraju
3 Replies

3. Shell Programming and Scripting

Lookup name from another file

Hi All, I want to lookup name for an id in col2 input from another file and add the name to each line. Input 1 comp100001_c0_seq1 At1g31340 30.40 569 384 11 3 1673 313 834 7e-62 237 comp100003_c0_seq1 At1g35370_2 35.00 80 50 ... (7 Replies)
Discussion started by: gina.lizar
7 Replies

4. UNIX for Dummies Questions & Answers

Lookup in Unix

Hi, I have an input file which contain below records: a,1 b,2 c,3 a,10 b,34 i have a reference file which contains below records: a,AA b,BB c,CC My required output is : (3 Replies)
Discussion started by: pandeesh
3 Replies

5. UNIX for Dummies Questions & Answers

Checking for unix hosts that do not have reverse lookup

Hi there i am not sure how to explain my problem. i need to run a script to give me the results of all my unix hosts that do not have reverse lookup activated (for lack of a better word), i need to give this to out Server guys to add it part of the AD rules. So what i need is a script to... (0 Replies)
Discussion started by: brian112
0 Replies

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

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

8. UNIX for Dummies Questions & Answers

lookup in unix

i am having one file which is of CSV format with two fields client_id and client_nbr.The sample data is lke below ABC,1250 CDE,1520 EFG,1000 PQR,1800 The client nbr for these clients change frequently.So i want to create one lookup file every week for the changed client and run a script... (3 Replies)
Discussion started by: dr46014
3 Replies

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

10. UNIX for Dummies Questions & Answers

Unix 8.2 and reverse Lookup

We have Unix configured as our external DNS, forward DNS is working properly, however Reverse lookup is not working. Any idea what the problem is? I have checked the named.boot and .rev file and everything seems to be correctly. However it appears that the reverse zone file in the named.boot... (2 Replies)
Discussion started by: cassy
2 Replies
Login or Register to Ask a Question