From owner-freebsd-questions Fri Dec 11 10:13:49 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id KAA06803 for freebsd-questions-outgoing; Fri, 11 Dec 1998 10:13:49 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from java.dpcsys.com (java.dpcsys.com [206.16.184.7]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id KAA06798 for ; Fri, 11 Dec 1998 10:13:48 -0800 (PST) (envelope-from dan@dpcsys.com) Received: from localhost (dan@localhost) by java.dpcsys.com (8.9.1a/8.9.1) with SMTP id KAA06260; Fri, 11 Dec 1998 10:13:36 -0800 (PST) Date: Fri, 11 Dec 1998 10:13:36 -0800 (PST) From: Dan Busarow To: Sue Blake cc: freebsd-questions@FreeBSD.ORG Subject: Re: carving up a file In-Reply-To: <19981211195018.15365@welearn.com.au> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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