Fixed length records containing 2 different records types with fixed field widths

Fixed length records containing 2 different records types with fixed field widths

Post by Janis Papanagno » Fri, 07 Jan 2005 04:48:20




> This is a fun one. I am beginning to receive fixed length record ASCII
> files but they contain 2 different record types.
> [...]

What game are you playing? You posted exactly the same question to
comp.lang.awk have got an answer already 20 hours ago to which you
also replied before reposting this again in c.u.s. You haven't even
enhanced your script considering Kenny's response.
 
 
 

Fixed length records containing 2 different records types with fixed field widths

Post by Rookie Car » Fri, 07 Jan 2005 05:28:41


Janis - I dont mean to be playing games, I'm just under a lot of
pressure and have 4 projects going at once. I just wanted as much imput
as I could get. I new to using news groups. I did not mean to offend
anyone.
I have removed my original post from comp.unix.shell and will dual post
again. I am grateful for the help I have recieved thus far a don't want
to offend anyone.  Your replies to my topic last week "Fixed legnth
fields on a single line" was very helpful.
Please accept my apology,
RookieCard

 
 
 

Fixed length records containing 2 different records types with fixed field widths

Post by Rookie Car » Fri, 07 Jan 2005 05:32:18


Quote:> I have removed my original post from comp.unix.shell and will NOT, no

NEVER dual post
again
 
 
 

Fixed length records containing 2 different records types with fixed field widths

Post by John W. Krah » Fri, 07 Jan 2005 09:07:32



> 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

You could do it in perl like this:

#!/usr/bin/perl

my ( $file, $aout, $bout ) = ( 'REC290.txt', 'RECTA.txt', 'RECTB.txt' );

open IN, '<', $file or die "Cannot open $file: $!";
open A,  '>', $aout or die "Cannot open $aout: $!";
open B,  '>', $bout or die "Cannot open $bout: $!";

$/ = \290;  # set IRS to record length
$\ = "\n";  # set ORS to newline

while ( my $rec = <IN> ) {
     if ( substr( $rec, 72, 1 ) eq 'A' ) {
         print A join ',', unpack 'A75 A45 A50 A75 A45', $rec;
         }
     else {
         print B join ',', unpack 'A45 A50 A45 A75 A75', $rec;
         }
     }

__END__

John
--
use Perl;
program
fulfillment

 
 
 

Fixed length records containing 2 different records types with fixed field widths

Post by Rookie Car » Fri, 07 Jan 2005 13:32:36


Thanks - John
I would love to use perl but the client I am working does not allow the
perl lib on their systems. Great post though, I will keep it mind next
time I have perl available.

I almost have it figured out in awk.
I just can't seem to figure out how to filter records based on the
position of a character in the record using awk.
The only output I would want would be records with an "A" in the 73
position

To keep with what I think is proper news group protocol I am going to
post my "new" question on comp.lang.awk as a new post as it may be of
more
use to some one else that way.
Thank very much for replying
Gary / Rookie Card

 
 
 

1. sorting fixed length records/fields (large files)

It seems that the standard unix system sort is pretty flexible for files
with variable length records (i.e. newline terminated records) and for
records which use some character to delimit the extent of the field.

But what about fixed-length fields?  It seems that the only way to
handle them is to try to find some character which is never going to be
in any record and use that as the field delimiter and then take offsets
into the first field as your sort keys.  That's pretty awful.  Is there
a better way to do it?

What about files containing fixed length records which are not
newline-delimited?

I know I could write such sorts in perl or C or whatever, but I want to
use the standard sort because I need to sort huge files (1+ gigabytes)
and I don't want to rewrite the chunking/merging capabilities built into
the standard sort.

Is the only alternative to buy some commercial product like SyncSort?

Thanks,
John Wiersba

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Printer script. HELP!

3. Pad records to fixed length.

4. Removing Linux ?

5. can sh remove \n's from fixed length ascii records?

6. Safe user-removing script needed

7. Editing fixed-length records

8. inn and nntp setting up

9. i've tried to sort fixed length records but it aint working

10. Editing fixed-length records (fwd)

11. Efficient reading of fixed-length records

12. KDE 2.1.x Fixed Width Fonts Free Feeble Font Fix

13. Fixed width antialiased fonts fixed in KDE 2.2?