From owner-freebsd-questions@FreeBSD.ORG Mon Jun 30 16:04:46 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 151AA37B401 for ; Mon, 30 Jun 2003 16:04:46 -0700 (PDT) Received: from adsl-64-161-78-226.dsl.lsan03.pacbell.net (adsl-64-161-78-226.dsl.lsan03.pacbell.net [64.161.78.226]) by mx1.FreeBSD.org (Postfix) with SMTP id 3E88143FD7 for ; Mon, 30 Jun 2003 16:04:45 -0700 (PDT) (envelope-from oremanj@adsl-64-161-78-226.dsl.lsan03.pacbell.net) Received: (qmail 2222 invoked by uid 1001); 30 Jun 2003 23:07:45 -0000 Date: Mon, 30 Jun 2003 16:07:45 -0700 From: Joshua Oreman To: Moritz Fromwald Message-ID: <20030630230745.GA2180@webserver.get-linux.org> References: <1057005399.1030.44.camel@mis3c.rtl.lan> <9944.1057008829@www28.gmx.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9944.1057008829@www28.gmx.net> User-Agent: Mutt/1.4.1i cc: questions@freebsd.org Subject: Re: Seperate fields in File X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jun 2003 23:04:46 -0000 On Mon, Jun 30, 2003 at 11:33:49PM +0200 or thereabouts, Moritz Fromwald wrote: > Hello, > > If you know how to write the script, then you would also know how to put > > it in a file too... > > > > Well, ain't no homework, just a newbie to script writing, thats all! > > So is there a way to split the content of a file up into an array? I don't know how to do it in sh-script. Mind some Perl? #!/usr/bin/env perl # split $1 into an array; separator is $2 our @Sections; our $Section = ""; open FILE, $ARGV[0] or die "$0: can't open $ARGV[0]: $!\n"; while () { if ($_ == $ARGV[1]) { push @Sections, $Section; } else { $Section .= $_; } } close FILE; # Now you have to do something with @Sections for this script to really be # useful. This just concatenates them to stdout (w/ the separator): print join ("$ARGV[1]\n", @Sections); # # Note that this script is NOT tested! # Run it like so: perl fieldsep.pl -- Josh > > TIA & regards > > Moritz Fromwald > > -- > +++ GMX - Mail, Messaging & more http://www.gmx.net +++ > Bitte l?cheln! Fotogalerie online mit GMX ohne eigene Homepage! > > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"