Mail Archives: djgpp/1998/07/22/21:47:19
Anne-Marie Chapman <ichapman AT sympatico DOT ca> writes:
> I guess that this question is good for Nate or Eli. I've written a
> program that takes a very large asc file and splits it. I'd like to use
> a gnu utility in place of mine. I'm sure that if there is a suitable
> utility it will be the best.
>
> The asc file consists of: -
> Test 1
> (A pile of test 1stuff)
> Test 2
> (Different test 2 stuff)
> Test … n
^^^ Is it a type or what file should be used after this line.
> What I generate is files 1 to n each containing the stuff for that
> test. I then run it through the gnu sort and cat it to another big
> file.
>
> The Test utility documentation is rather terse and I'm not able to
> determine with confidence what these utilities do. Is there one that
> does anything like what I need?
You can try gawk.
--- test.awk ---
BEGIN {
# Remove old files.
system ("rm -f [0-9a-zA-Z].tst");
# Set default output file.
ofile = "1.tst";
}
// {
if (match($0, /^Test[ \t]+[0-9a-zA-Z][ \t]*$/)) {
# Change filename.
ofile = sprintf("%s.tst", gensub(/^Test[ \t]+([0-9a-zA-Z])[ \t]*/, "\\1", "g", $0));
}
else {
# Append to the current file.
print $0 >> ofile
}
}
--- end of test.awk ---
Command-line:
> gawk -f test.awk < test.asc
Program above allows any number of whitespaces around file name
(Test<whitespaces>N<maybe_whitespaces>), if input file is generated
automatically, you may want to use exact number of spaces.
HTH.
- Raw text -