I had a file with 150k records in it and I ran a tr on it to remove all new lines/CR which created one large record(whoops). Is there a way to add a \n after every 39th character without using 'dd' to turn it back into the original format?
#!/usr/bin/perl
# @(#) p1 Demonstrate read fixed-length records.
# See Recipe 8.15 perl Cookbook, Ed 1.
use warnings;
use strict;
my ($debug);
$debug = 0;
$debug = 1;
my ($lines) = 0;
my ( $f, $file );
my ($record);
my ($RECORDSIZE) = 10;
$f = shift || die " Need a file name.\n";
open( $file, "<", $f ) || die " Cannot open $f\n";
until ( eof($file) ) {
$lines++;
read( $file, $record, $RECORDSIZE ) == $RECORDSIZE
or die " Short read on $f at line $lines\n";
print $record, "\n";
}
print STDERR " ( Lines written: $lines )\n";
exit(0);
which can be called from a ksh script:
#!/bin/ksh -
# @(#) s1 Demonstrate perl reading fixed-length records.
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1) tr perl
FILE=data1
tr -d '\n' <data0 >$FILE
echo
echo " Input file $FILE:"
cat $FILE
echo
echo
echo " Output from perl script:"
./p1 data1
exit 0