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

jerry w jerrywone@gmail.com
Sun Oct 23 07:10:32 EDT 2016


Flawed spec: WinBlow$ on a Linux list...

On Thu, Oct 20, 2016, 16:31 William Sutton via Novalug <
novalug@firemountain.net> wrote:

> Except he didn't have Perl.
>
> William Sutton
>
> On Thu, 20 Oct 2016, James Ewing Cottrell III via Novalug wrote:
>
> > I think we have a winner here, but be aware that this command will nuke
> > trailing spaces, so each line will not be 184 characters. I'd say this is
> > mostly what you want, but I'd call it a flaw in DD's conversion
> offerings.
> >
> > Actually, Rich didn't add a CR, but that's easy to do by piping to
> >
> >       sed 's/$/\r/'
> >
> > or maybe dos2unix. Why a CR is desired is a mystery, but since it's part
> of
> > the Specs, we must honor it.
> >
> > I played around with trying to use READ and ECHO, something like
> >
> >       tr -d \\012 < /etc/passwd |
> >       sed 's/ /  /g' |
> >       while IFS= read -N20 x; do echo "$x"; done |
> >       cat -vet | less
> >
> > And that DID give me what I wanted, including the Trailing Spaces.
> >
> > Ultimately tho, trying to shoehorn the existing GNUtilities, while
> > instructive, probably takes way longer than writing a simple filter:
> >
> >       perl -e 'print "$x\r\n" while sysread(STDIN,$x,182)'"
> >
> > JIM
> >
> > On 10/17/2016 4:51 PM, Rich Kulawiec via Novalug wrote:
> >> On Mon, Oct 17, 2016 at 08:19:08PM +0000, Ide, Jim J. - US via Novalug
> >> wrote:
> >>> 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.
> >>
> >>      dd if=inputfile of=outputfile cbs=182 conv=unblock
> >>
> >> ---rsk
> >> **********************************************************************
> >> 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
> >
> **********************************************************************
> 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