Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Dec 1998 10:13:36 -0800 (PST)
From:      Dan Busarow <dan@dpcsys.com>
To:        Sue Blake <sue@welearn.com.au>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: carving up a file
Message-ID:  <Pine.BSF.3.96.981211100709.15801F-100000@java.dpcsys.com>
In-Reply-To: <19981211195018.15365@welearn.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 11 Dec 1998, Sue Blake wrote:
> I've got a 2 meg text (RTF) file to split into a dozen files, one for
> each chapter, after each time it is edited.
> 
> There is a distinctive string at the beginning of each chapter,
> another could be added to the file, or I could go by line numbers.

Try this, untested but safe unless you have files named chapter.1,
chapter.2 ... in the directory.  Assumes DISTINCTIVE STRING is the
first line of the file as well as preceding all other chapters.
Run with

$ ./splitchapters.pl < source_file

#!/usr/local/bin/perl
$chapternumber = 0; 
while(<>) {
    if(/DISTINCTIVE STRING/) {
        close(O) if(O);
        $chapternumber++;
        $out = "chapter." . $chapternumber;
        open(O, ">$out"); 
    }
    print O "$_";
}   
close(O);


Dan
-- 
 Dan Busarow                                                  949 443 4172
 Dana Point Communications, Inc.                            dan@dpcsys.com
 Dana Point, California  83 09 EF 59 E0 11 89 B4   8D 09 DB FD E1 DD 0C 82


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.96.981211100709.15801F-100000>