Flat file manipulation, (this could be a tough one)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Flat file manipulation, (this could be a tough one)
# 1  
Old 01-09-2008
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! Smilie
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  
Old 01-10-2008
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  
Old 01-10-2008
@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
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed flat file manipulation

Hello, I have a large flat file where i need to change data in columns 131-133 based on what is in columns 172-173. I am not sure if I need to read the file line by line and make the change or if I can do this in a single statement. thank you (3 Replies)
Discussion started by: gblmin
3 Replies

2. IP Networking

This looks like a tough routing issue

Hi, The default gateway (172.17.220.1) cannot be pinged via the default interface bond0 (172.17.220.231), but can be pinged via interface eth1 (10.201.135.73). # ping -I eth1 172.17.220.1 PING 172.17.220.1 (172.17.220.1) from 10.201.135.73 eth1: 56(84) bytes of data. 64 bytes from... (4 Replies)
Discussion started by: aixlover
4 Replies

3. Shell Programming and Scripting

A very tough exercise

hello everyone!:) I have an exercise which I think is difficult for beginner like me. Here is the exercise Create a shell script, which takes a directory as command line argument. Script displays ten first lines from every text file in that directory. After displaying the lines from the... (1 Reply)
Discussion started by: googlevn
1 Replies

4. Shell Programming and Scripting

Flat file manipulation

Hi I have flat file with 100 records ,I need to fabricate data into flat file . ex: file.txt 102345 1000 200 300 ............................... .............................. 102346 2000 300 4000 In above file the 4th row, 1 st column valu to be increment by 1 and rest of... (13 Replies)
Discussion started by: mohan705
13 Replies

5. UNIX for Dummies Questions & Answers

tough parsing

I have a string as "Period= 20090531 Client Name= Clayton Lumbar Company Destination= MD" I want to parse the string and store it in 3 different variables. $period (should get value 20090531) $client (should get value "Clayton Lumbar company") $dest (should get value MD) How can I do... (3 Replies)
Discussion started by: paruthiveeran
3 Replies

6. Shell Programming and Scripting

Flat File column manipulation

Hi All, I have a tab delimited input file with say 4 fields (columns) as below : 0000443 1AGPR061 2006 Daiml 0002198 1B3XG0K2 1989 Chdds 0002199 1Bd64J0L 1990 Ch34s 0002275 1B3s4J0K 1989 Chadys 0002276 1B465302 2002 Dageml 0002290 1B45430K 1989 Cays I want the 2nd column in file to... (5 Replies)
Discussion started by: net
5 Replies

7. UNIX for Advanced & Expert Users

Tough Substituion command

I have lines like: Mg2.qns W=0.175u Mg2.qpsb W=0.175u Mg4.qns W=0.175u Mg4.qpsb W=0.175u Which I need to become: Mg2.qns W=wmg2qns Mg2.qpsb W=wmg2qpsb Mg4.qns W=wmg4qns Mg4.qpsb W=wmg4qpsb To acheive this individually line by line I use a command like:... (3 Replies)
Discussion started by: ggggdddd
3 Replies

8. Shell Programming and Scripting

Seems the Shell Script is very tough

Guys plz respond. (1 Reply)
Discussion started by: prince_of_focus
1 Replies
Login or Register to Ask a Question