Path: utzoo!utgpu!watmath!uunet!cs.utexas.edu!csd4.milw.wisc.edu!uakari.primate.wisc.edu!ctrsol!emory!arnold
From: arnold@mathcs.emory.edu (Arnold D. Robbins {EUCC})
Newsgroups: gnu.utils.bug
Subject: Re: gawk questions
Message-ID: <4261@emory.mathcs.emory.edu>
Date: 9 Aug 89 19:32:48 GMT
References: <890808-150138-2345@Xerox>
Reply-To: arnold@emory.UUCP (Arnold D. Robbins {EUCC})
Distribution: gnu
Organization: Math and Computer Science, Emory University, Atlanta GA
Lines: 40

In article <890808-150138-2345@Xerox> Leisner.Henr@XEROX.COM (Marty) writes:
>1) I can't seem to get FILENAME to work.  Is it available in a begin block?
>I played around with it but haven't seen it do anything useful yet.

This is a question for the language lawyers.  The way gawk thinks, FILENAME
is set only once files are actually being processed.  That doesn't happen
until after the BEGIN block is run.  FILENAME is initialized to "-", which
is its value inside a BEGIN block.  I think Unix awk is wrong on this one,
although the Bell Labs folks may disagree.

>I ended up doing this:
>BEGIN {
>	printf "; File %s converted ", ARGV[ARGC-1]
>	system("date");
>}

This is more logical, but it presumes knowledge that only one file
at a time will be converted.  It is also incorrect if the data file
is on standard input, in which case ARGC == 1 and ARGV[ARGC-1] is "gawk".

>BTW -- I started by using $ARGV[$ARGC-1] -- this dumped core.

You've referenced a non-existant field inside the BEGIN block, when fields
don't even exist at all.  It should still not dump core, and in fact this
bug has been fixed in the (upcoming) 2.11 release.

>2) I want to do some substitions of the form
>	0xnnnnn to 0nnnnH
>I'm not sure I see how to do it.  Any good recommendations? 

My first thought is to use sed, with the \(...\) construct, but actually
it should be doable in awk, using the split and sub builtin functions.

2.11 is coming along nicely.  A call for pre-testing will come out
Real Soon Now.
-- 
Arnold Robbins -- Emory University Computing Center | Unix is a Registered
DOMAIN: arnold@unix.cc.emory.edu		    | Bell of AT&T Trademark
UUCP: gatech!emoryu1!arnold  PHONE: +1 404 727-7636 | Laboratories.
BITNET: arnold@emoryu1	     FAX:   +1 404 727-2599 |         -- Donn Seeley