Date: Mon, 30 Jun 2003 16:07:45 -0700 From: Joshua Oreman <oremanj@webserver.get-linux.org> To: Moritz Fromwald <mfromwald@gmx.at> Cc: questions@freebsd.org Subject: Re: Seperate fields in File Message-ID: <20030630230745.GA2180@webserver.get-linux.org> In-Reply-To: <9944.1057008829@www28.gmx.net> References: <1057005399.1030.44.camel@mis3c.rtl.lan> <9944.1057008829@www28.gmx.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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...
> >
> <snip homework, script,....>
> 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 (<FILE>) {
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 <file-to-split> <separator-line>
-- 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"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030630230745.GA2180>
