Computing.Net > Forums > Database > Line break at position 512 in text

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Line break at position 512 in text

Reply to Message Icon

Name: gazdag6
Date: December 3, 2008 at 16:10:58 Pacific
OS: NA
CPU/Ram: NA
Product: NA
Comment:

Hi there guys, I am working with a text file that always has 1024 characters per line. The format for my db requires each line limit to be 512. Is there a way to insert a "return" in a text doc that after character 512 which is an asterisk, to insert a return? My db seems to error out each time I try to import. The db I am using is access and the source doc is a 1024 character per line text file.

Thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: FishMonger
Date: December 6, 2008 at 05:57:28 Pacific
Reply:

You didn't give any indication on which scripting language you wanted to use. If you want to use Perl, I can show you several methods to split the lines.

Here's one method. For the purpose of this example, I've left out nearly all of the normal error checking/handling.


#!/usr/bin/perl

use warnings;
use strict;

open my $file, '<', $ARGV[0] or die $!;
while(<$file>) {
s/(?<=.{512})/\n/;
print;
}



Assuming the script was called fixlines.pl and the name of the text file to process is db.txt and you want to put the results into fixed.txt, you'd execute the script like this:

C:\>fixlines.pl db.txt > fixed.txt

Another option would be to do a Perl 1 liner command. Here's the 1 liner command that does an inline edit of the original file as well as creates a backup of the original file.

C:\>perl -pi.bak "s/(?<=.{512})/\n/;" db.txt


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Database Forum Home


Sponsored links

Ads by Google


Results for: Line break at position 512 in text

help! blank lines (break, compute) www.computing.net/answers/dbase/help-blank-lines-break-compute/481.html

Error in VB TRANSFORM code www.computing.net/answers/dbase/error-in-vb-transform-code/113.html

MS acess at multiple locations www.computing.net/answers/dbase/ms-acess-at-multiple-locations/196.html