Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Fixed length records containing 2 different records types with fixed field widths
This is a fun one. I am beginning to receive fixed length record ASCII
files but they contain 2 different record types.

- All records are 290 in length but have different field widths.
- The field widths for each of the 2 record types is fixed
- One record type always begins with an "A" in the 73 position.
- I need to parse the records to 2 new comma separated text files.

I have bought 2 books and researched and still cannot get the syntax
even close.
I need to do something like this:

(Please forgive the sloppy syntax, I'm a rookie)

gawk {If  ".{75}"= A}
{ print $1, $2, $3, $4, $5}" FIELDWIDTHS="75 45 50 75 45" OFS=,
RECTA.txt;
else
{ print $1, $2, $3, $4, $5}" FIELDWIDTHS="45 50 45 75 75" OFS=,
>RECTB.txt;
REC290.txt  <<<< That's my ASCII file

In other words, I want to parse REC290.txt to RECTA.txt for (the
"A" in the 73 position) record type and parse the other record type
(Which has no distinguishing characteristics) to RECTB.txt
Any help would be very gratefully appreciated.


Report this thread to moderator Post Follow-up to this message
Old Post
Rookie Card
01-07-05 08:55 AM


Re: Fixed length records containing 2 different records types with fixed field widths
In article <1104881851.636834.302920@z14g2000cwz.googlegroups.com>,
Rookie Card <mis_pro@yahoo.com> wrote:
>This is a fun one. I am beginning to receive fixed length record ASCII
>files but they contain 2 different record types.
>
>- All records are 290 in length but have different field widths.
>- The field widths for each of the 2 record types is fixed
>- One record type always begins with an "A" in the 73 position.
>- I need to parse the records to 2 new comma separated text files.

I would imagine something like:

BEGIN	{
fw[0]="45 50 45 75 75"
fw[1]="75 45 50 75 45"
OFS=","
}
{FIELDWIDTHS = fw[substr($0,73,1) == "A"];$0=$0}
{ ... rest of program goes here ... }


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
01-07-05 08:55 AM


Re: Fixed length records containing 2 different records types with fixed field widths
William -
The files don't have leading spaces but do have spaces in the middle
Like this:

200409113  834736A90028
CLIENTID 00VNI112B92658
CLIE  ID000VNI118S98271
200411   34129983A93065

The spaces are never consistant as they represent a fixed lenth field
and the data is not always the same legnth. Although the posistion of
the records identifier ( A ) is always the same if you count the
spaces. (Fixed length records with fixed field widths)
I also tried awk '/A/' REC18.txt
the output returned all records.


Report this thread to moderator Post Follow-up to this message
Old Post
Rookie Card
01-10-05 08:56 PM


Re: Fixed length records containing 2 different records types with fixed field widths
William,
What version of gawk are you using? I am using gnu gawk 3.1.3
We used the same script and the same data.
It filtered the records perfect for you and not for me.
Then the only difference would be the executable.
Right? I could be mistaken. I do that alot.

Well, there is always the X factor. My problem may be between the Chair
and the Keyboard.
If you could tell what version of gawk you are using that would be very
helpful.
Gary


Report this thread to moderator Post Follow-up to this message
Old Post
Rookie Card
01-10-05 08:56 PM


Re: Fixed length records containing 2 different records types with fixed field widths
Rookie Card wrote:
> William,
> What version of gawk are you using? I am using gnu gawk 3.1.3
> We used the same script and the same data.
> It filtered the records perfect for you and not for me.
> Then the only difference would be the executable.
> Right? I could be mistaken. I do that alot.
>
> Well, there is always the X factor. My problem may be between the
Chair
> and the Keyboard.
> If you could tell what version of gawk you are using that would be
very
> helpful.
> Gary

GNU Awk 3.0.3 and Kernighan's awk and mawk.

I've converted spaces to commas and saved this in file "data":

200409113,,834736A90028
CLIENTID,00VNI112B92658
CLIE,,ID000VNI118S98271
200411,,,34129983A93065

This command line
awk "\"A\"==substr($0,18,1)" data

produces this output, using any of those awks:
200409113,,834736A90028
200411,,,34129983A93065


Report this thread to moderator Post Follow-up to this message
Old Post
William James
01-10-05 08:56 PM


Re: Fixed length records containing 2 different records types with fixed field widths
Ed Morton wrote:
>Rookie Card wrote:
> 
>
>
>Given your other postings where you didn't use the above syntax, I
doubt
>if gawk was really the problem. Try it again using exactly the syntax
above.

Rookie, it would be incredible if gawk was the problem.  The older
version
worked for me and the newer version almost certainly will.


Report this thread to moderator Post Follow-up to this message
Old Post
William James
01-10-05 08:56 PM


Re: Fixed length records containing 2 different records types with fixed field widths
Ed -
awk '{ print substr($0,18,1) }' REC18.txt
A
B
S
A

Then I try
awk '{ print "A"==substr($0,18,1) }' REC18.txt
0
0
0
0
This is with the example data: REC18.txt
20040911324834736A90028
CLIENTID000VNI112B92658
CLIENTID000VNI118S98271
20041112534129983A93065
Thanks
Gary / Rookie Card


Report this thread to moderator Post Follow-up to this message
Old Post
Rookie Card
01-10-05 08:56 PM


Re: Fixed length records containing 2 different records types with fixed field widths
Thanks Kenny,
That puts me different direction. I'm still fighting syntax errors but
slowly making progress.
I will post the final code when I get it figured out. If I get stuck,
which I probably will, I'll post the code and detail where it is
choking.


Report this thread to moderator Post Follow-up to this message
Old Post
Rookie Card
01-12-05 01:55 PM


Re: Fixed length records containing 2 different records types with fixed field widths
I need to backup a bit. My client keeps changing their requirements. (6
new files with 14 records types)
Lets forget the 2 different record types to two different files for
now.
I've got the parsing and field spliting figured out. (Thanks to John,
Janis and Jim's posts)

I just cant seem to figure out how to filter records based on the
position of a character in the record using awk.

here's the example:
The only output I would want would be records with an "A" in the 18
position

input file would look like this: (let call it REC18.txt)
20040911324834736A90028
CLIENTID000VNI112B92658
CLIENTID000VNI118S98271
20041112534129983A93065
The output I want would look like this: (Lets call it RECA.txt)
20040911324834736A90028
20041112534129983A93065
I tried:

gawk 'BEGIN { print substr($0,18)  == "A"}' REC18.txt >RECA.txt
Output was:
1

And tried:
gawk ' { print substr(18,1) =="A"}' REC18.txt >RECA.txt
Output was:
0
0
0
0
0
gawk 'BEGIN { print substr($0,18,1)  == "A"}' REC18.txt >RECA.txt
Output was:
1
amoung many "tries"

I RTFM, Debug for hours and searched news groups. Its got to be there.
Right?
I thank you in advance for your help.
Gary / Rookie Card


Report this thread to moderator Post Follow-up to this message
Old Post
Rookie Card
01-12-05 01:55 PM


Re: Fixed length records containing 2 different records types with fixed field widths
Ed -
awk '{ print substr($0,18,1) }' REC18.txt
A
B
S
A

Then I try
awk '{ print "A"==substr($0,18,1) }' REC18.txt
0
0
0
0
This is with the example data: REC18.txt
20040911324834736A90028
CLIENTID000VNI112B92658
CLIENTID000VNI118S98271
20041112534129983A93065
Thanks
Gary / Rookie Card


Report this thread to moderator Post Follow-up to this message
Old Post
Rookie Card
01-12-05 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:43 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.