Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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!

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/perluse 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

![]() |
![]() |
![]() |

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