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
Flat File in HP-UX Krishnaramjis Shell Programming and Scripting 0 06-02-2008 08:24 PM
Flat file Krishnaramjis Shell Programming and Scripting 9 05-08-2008 07:28 PM
Help with a Flat File!!! kumarsaravana_s Shell Programming and Scripting 11 06-07-2007 08:15 PM
Help with a flat file!!! kumarsaravana_s Shell Programming and Scripting 3 04-16-2007 04:58 AM
XML to flat file balireddy_77 Shell Programming and Scripting 2 04-13-2007 02:57 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-09-2008
mrbungle50's Avatar
Registered User
 

Join Date: Jan 2008
Posts: 1
Flat file manipulation, (this could be a tough one)

Howdy everyone, I have need of a scripting brain to help me through the following issue:
*This will help if I explain what I am doing this for and then it may make sense.
I need to change a flat file to prepend a 3 digit code to a certain field in the file going on the value in another scetion of the same line.
Confused? I thought so!
Anyhow here goes.
In the attached flat file there is a field 4 digits at position 155 which is an Australian post-code (zip code). I need my script to read this value and if it begins with a certain number (eg: 9XXX for Western Australia) take a pre-defined TZ 3 digit code (eg: starts with a 9 > code will equal 900) and take this TZ 3 digit code and insert it at the point 216, then at 237 and finally at 258 on the same line. These are three phone numbers (home, work, mobile)
I have tried a few awk attempts but not geting the syntax correct and feel I need something bigger and stronger than this?
Please have a read of the attached text file and you'll see it is just a list of name addresses and phone numbers. NB: I have changed some of the umbers to be X and Y for confidentiality.
This is for a dialler application and sadly it uses are codes for working out what time zone the record is in. In Australia area codes span different time zones, but post codes do not. So the use of postal codes is the most logical choice but in order to get the dialler application to dial using it's time zones functionality I must give it area codes to work with.
Does this make sense?
Please email or contact me at any time if you need clarification on anything.
Thanks again
Craig
MrBungle50
PS: I am in Australia
Attached Files
File Type: txt Modified_COLLECT7_download file.txt (12.7 KB, 5 views)
Reply With Quote
Forum Sponsor
  #2  
Old 01-09-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,933
With GNU Awk:

Code:
awk '$2~/^9/{$4=$6=$8=9000}1' OFS= FIELDWIDTHS="154 4 58 4 17 4 17 4 109" data
Reply With Quote
  #3  
Old 01-10-2008
rikxik's Avatar
Registered User
 

Join Date: Dec 2007
Posts: 105
@mrbungle

Code:
#!/usr/bin/sh

nawk '{if(/^HDRDIALLER/ || /^TRLDOWNLOAD/) {
                print
        } else {
                ins="00"substr($0,155,1)
                print substr($0,1,216)(ins)substr($0,218,20)(ins)substr($0,239,20)(ins)substr($0,259)
        }
}' $1 > $2
Usage:
Code:
cl.sh collect.txt tz_added.txt
HTH
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:06 AM.


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