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!
> 
> _______________________________________________
> [EMAIL PROTECTED] mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "[EMAIL PROTECTED]"
_______________________________________________
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to