![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Lookup with a file | pavan_test | UNIX for Dummies Questions & Answers | 5 | 07-21-2006 07:57 AM |
| Reverse lookup | jpalmer320 | IP Networking | 1 | 05-21-2004 06:36 AM |
| Unix 8.2 and reverse Lookup | cassy | UNIX for Dummies Questions & Answers | 2 | 04-12-2004 02:18 PM |
| reverse lookup again | Westy564 | IP Networking | 1 | 01-12-2004 08:37 AM |
| file lookup | gillbates | UNIX for Dummies Questions & Answers | 6 | 12-12-2003 11:04 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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"
Regards |
|
#3
|
|||
|
|||
|
any suggestions how to do this ???
|
|
#4
|
|||
|
|||
|
thanks a lot
|
|
#5
|
|||
|
|||
|
i need to pass the input file name as a parameter and get the same file as the output after set operation
|
|
#6
|
||||
|
||||
|
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
}
|
||||
| Google The UNIX and Linux Forums |