The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-09-2008
mrbungle50's Avatar
mrbungle50 mrbungle50 is offline
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

Last edited by mrbungle50; 02-28-2009 at 02:28 AM.. Reason: incorrect examples
  #2 (permalink)  
Old 01-10-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

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

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

Join Date: Dec 2007
Posts: 250
@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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0