Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Chop one record into many records 1

Status
Not open for further replies.
Jun 13, 2001
7
US
How do I take a file of nnnn bytes with no carriage returns and chop it into lines of nn bytes followed by a CR

Thanks for yer help

George
 
Check out the "split" command. Remember, amateurs built the Ark, professionals built the Titanic.
 
Actually success was premature I am not on solaris I and AIX I can split -bnn and get many files all of the required length each with one record in I then cat these all back together again hoping to end up with a file of just 1360 bytes CR 1360 bytes CR 1360 bytes CR etc but alas I just get back to the file I started with - one long record - any ideas ?
 
George,

Use the LF character rather than CR, UNIX uses Line Feed to separate lines in a text file.

Get back to us if you're still having problems, a Perl script to do that job would be very easy and if you don't have perl (it's on one of the AIX cd's actually) then it could probably be done in ask . Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
OK so what I really wanted to do was split one record into many records each seperataed by a LF and not a carriage return - is PERL my best option how do I tell if we have it installed ?
Thanks
George
 
I am not a programmer so I don't know the difference between a LF and CR in the file you are splitting. However, for what it is worth: I was able to split a file then vi the split files and add a line at the bottom by enter o to add the line. I then cat'ed them back into one file and the blank lines were still there.
Does that help? Remember, amateurs built the Ark, professionals built the Titanic.
 
Mike Lacey provided me with the following PERL script
it is currently executing
/usr/bin/perl -w
use strict; # just to keep me honest

my $line_length = 1360;

my $whole_file, $a_line;

$whole_file = <>;
# slurp the file into a variable.
while($whole_file){
$a_line = substr($whole_file,0,$line_length)
# get the firsta $line_length chars
print &quot;$a_line\n&quot;;
# print that
$whole_file = substr($whole_file,$line_length)
# get rid of first 1360 chars


I will let you know the results
 
finally after much error this worked - crude tho it may be
$ more george.pl
#!/usr/bin/perl

open(DOG,&quot;/dw01/app/pwmart47/BkupFiles/custacct.sptd.200106130424&quot;) || die &quot;Coul
dn't open DOG\n$!\n&quot;;

open(CAT,&quot;>/dw01/app/pwmart47/BkupFiles/george.sptd.out&quot;) || die &quot;Couldn't open
CAT \n$!\n&quot;;


my $line_length = 1360;


$whole_file = <DOG>;
for($y=1; $y<=3404; $y++) {
$a_line = substr($whole_file,0,$line_length);
print CAT &quot;$a_line\n&quot;;
$whole_file = substr($whole_file,$line_length);

}

close(DOG);
close(CAT);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top