[Novalug] Reading a fixed length text file with no record separator

Ide, Jim J. - US jim.ide@caci.com
Tue Oct 18 11:15:28 EDT 2016


List,

Jared's suggestion to use 'fold' solved my problem.
Thanks to everyone who replied.

Jim



-----Original Message-----
From: William Sutton [mailto:william@trilug.org] 
Sent: Monday, October 17, 2016 4:53 PM
To: Jared Scott
Cc: Ide, Jim J. - US; novalug@firemountain.net
Subject: Re: [Novalug] Reading a fixed length text file with no record separator

even better.  and I learned a new tool!

William Sutton

On Mon, 17 Oct 2016, Jared Scott wrote:

> If you have coreutils you can use `fold -w182 <filename>` 
> http://gnuwin32.sourceforge.net/packages/coreutils.htm
> 
> 
> 
> On Mon, Oct 17, 2016 at 4:38 PM William Sutton via Novalug 
> <novalug@firemountain.net> wrote:
>       split -b 182 file.txt part.
>       for f in part.*; do cat $f |sed -e "s/$/\r\n/" >>newfile.txt;
>       done;
>       rm part.*
>
>       William Sutton
>
>       On Mon, 17 Oct 2016, Ide, Jim J. - US wrote:
>
>       > Thanks again for replying.
>       >
>       > I think split will create a separate file for each record.
>       > I want all output records to be copied into a single file,
>       with each record separated by CRLF.
>       >
>       >
>       >
>       > -----Original Message-----
>       > From: William Sutton [mailto:william@trilug.org]
>       > Sent: Monday, October 17, 2016 4:26 PM
>       > To: Ide, Jim J. - US
>       > Cc: novalug@firemountain.net
>       > Subject: Re: [Novalug] Reading a fixed length text file with
>       no record separator
>       >
>       > actually, idiot me.
>       >
>       > if you have split available, look at man split, particularly
>       -b (bytes)
>       >
>       > William Sutton
>       >
>       > On Mon, 17 Oct 2016, Ide, Jim J. - US via Novalug wrote:
>       >
>       >> Hello,
>       >>
>       >> I have a very large text file that contains fixed length
>       records (each record is 182 characters).
>       >> There is no record separator character at the end of each
>       record (no \n).
>       >> Starting at the first character of this file, I want to read
>       182
>       >> characters, write those 182 characters to an output file with
>       CRLF
>       >> appended, read the next 182 character, write them to the
>       output file
>       >> with CRLF appended, and so on, until the end of input file.
>       >>
>       >> I am on a Windows 7 machine, but I have awk, dd, and a few
>       other unix
>       >> tools ported to Windows available.
>       >>
>       >> Any ideas on solving this problem?
>       >>
>       >> Thanks,
>       >> Jim
>       >>
>       **********************************************************************
>       >> The Novalug mailing list is hosted by firemountain.net.
>       >>
>       >> To unsubscribe or change delivery options:
>       >> http://www.firemountain.net/mailman/listinfo/novalug
>       >>
>       >
>       **********************************************************************
>       The Novalug mailing list is hosted by firemountain.net.
>
>       To unsubscribe or change delivery options:
>       http://www.firemountain.net/mailman/listinfo/novalug
> 
> 
>




More information about the Novalug mailing list