[thelist] How to split a long text file into separate files
Plunkett, Matt
MPlunkett at MSA.com
Mon Oct 15 14:05:20 CDT 2001
Untested, but should work...might be some special chars in the regexp. In
perl:
use strict;
my $input_file = "longfile.txt";
my $first_flag = 1;
my $output_count = 1;
my $output_file;
my $line;
open(IN, "$input_file") or die "Error opening $input_file: $!";
while (<IN>)
{
$line = $_;
if (/<!--Record Number:1-->/i)
{
if ($first_flag == 1)
{
$first_flag = 0;
}
else
{
close(OUT);
}
$output_count++;
$output_file = "chop" . $output_count;
open(OUT, ">$output_file") or die "Error opening
$output_file: $!";
}
print OUT $line;
}
close(IN);
-----Original Message-----
From: Michael Barrett [SMTP:mbarrett at triad.rr.com]
Sent: Monday, October 15, 2001 2:43 PM
To: thelist at lists.evolt.org
Subject: [thelist] How to split a long text file into
separate files
Listers,
I have this long text file,
The result of a mail merge from an excel document.
The data in the excel doc needs to be made available on a web site.
There is
no server side scripting available.
I created a neat and clean table layout to hold the data, brought
the html
into word, then merged with the data in the excel doc to produce a
long
document with 69 tables, then saved as text.
I want each table in a separate file.
Short of an afternoon of copying and pasting, is there a handy way
to
(automated) way to hack the document into parts? Possibly using
emacs or
something similar?
Each table is proceeded by a comment tag, and followed by two line
breaks
like so...
<!--Record Number:1-->
<table>
Foo
</table>
<br>
<br>
Thoughts?
--
Michael Barrett
-O^O-
-
mbarrett at triad.rr.com
AIM: device55
---------------------------------------
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to:
http://lists.evolt.org Workers of the Web, evolt !
More information about the thelist
mailing list