Leisner.Henr@XEROX.COM (Marty) (08/09/89)
I'm learning how to use awk. I started to use GAWK 2.10 on my sun386i
since the documentation seemed substantially complete then the Unix
version.
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.
I ended up doing this:
BEGIN {
printf "; File %s converted ", ARGV[ARGC-1]
system("date");
}
BTW -- I started by using $ARGV[$ARGC-1] -- this dumped core.
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?
(I'm converted assembler syntax from one assembler to another so I'd want
to be able do do something
and di,*0x000F
into
and di,000FH
)
marty
ARPA: leisner.henr@xerox.com
GV: leisner.henr
NS: leisner:wbst139:xerox
UUCP: hplabs!arisia!leisner
arnold@mathcs.emory.edu (Arnold D. Robbins {EUCC}) (08/10/89)
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