www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/22/21:47:19

Sender: bukinm AT SunKEDR30 DOT inp DOT nsk DOT su
To: djgpp AT delorie DOT com
Subject: Re: Test Utilities
References: <35B66B5D DOT 1202 AT sympatico DOT ca>
From: M DOT A DOT Bukin AT inp DOT nsk DOT su
Date: 23 Jul 1998 08:37:24 +0700
In-Reply-To: Anne-Marie Chapman's message of Wed, 22 Jul 1998 18:44:46 -0400
Message-ID: <p6taf61bb56.fsf@SunKEDR30.inp.nsk.su>
Lines: 55

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019