The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-02-2008
Registered User
 

Join Date: Jun 2007
Posts: 70
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.
Reply With Quote
Forum Sponsor
  #2  
Old 05-03-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,314
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
Reply With Quote
  #3  
Old 05-03-2008
Registered User
 

Join Date: Jun 2007
Posts: 70
any suggestions how to do this ???
Reply With Quote
  #4  
Old 05-03-2008
Registered User
 

Join Date: Jun 2007
Posts: 70
thanks a lot
Reply With Quote
  #5  
Old 05-03-2008
Registered User
 

Join Date: Jun 2007
Posts: 70
i need to pass the input file name as a parameter and get the same file as the output after set operation
Reply With Quote
  #6  
Old 05-03-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,019
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
}
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0