Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: How can I c...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 14 of 17 Topic 2207 of 2236
Post > Topic >>

Re: How can I check if a file exists in gawk?

by gazelle@[EMAIL PROTECTED] (Kenny McCormack) Mar 30, 2008 at 03:35 PM

In article
<853cada4-f51a-47b8-b39e-ea056c00d1d4@[EMAIL PROTECTED]
>,
mjc  <mjcohen@[EMAIL PROTECTED]
> wrote:
>On Mar 29, 2:18 pm, Ed Morton <mor...@[EMAIL PROTECTED]
> wrote:
>>
>....
>> What contortions? Could you give a small example of the problem?
>>
>.....
>>         Ed.
>
>I wrote a program in gawk to compare the results of a computation
>(written in assembly language with debugging info) with a simulation
>of the computation. In addition, the program also read the assembly
>listing so it would know what debugging info could be written and read
>its own source so it would know what debugging info was being looked
>for.

Basically, getline is only _needed_ when you are reading more than one
file at a time (i.e., "in parallel").  Now, having said that, some
people find its use (in those cases where it is not necessary) to be
aesthetically appealing - and others don't.  Obviously, there's no
accounting for taste.  I agree with Ed's basic position on the matter,
which is that using getline appeals to people who don't quite get "awk
qua awk".

Your example certainly fits the classic "people think they need getline,
but they don't" archetype.  That is, your program should (in the Ed/Kenny
sense of the word "should") be written:

ARGIND == 1 {
	# Do stuff for file 1
	next
	}
ARGIND == 2 {
	# Do stuff for file 2
	next
	}
ARGIND == 3 {
	# Do stuff for file 3
	next
	}
{
# else do stuff for file 4
# Note that for this, the last file, you can also use all the usual
# AWK pattern/action stuff
}

Note: I hope I got the ARGIND stuff right (ARGIND is, AFAIK,
gawk-specific).  I normally use TAWK, which has a variable called ARGI,
which is the same as gawk's ARGIND, except that it is higher by one (so
the first file is: ARGI == 2 {})

Notes:
1) Yes, it is unfortunate that you can only use the "automatic patterns"
in the last file.  But this is (obviously) the same as if using getline.
2) The real point of using the above style in place of getline is that
you specify the files to be read on the command line, rather than
hard-coding them into the script.  This is a Good Thing, although many
see it as a minus at first sight.




 17 Posts in Topic:
How can I check if a file exists in gawk?
Boltar <boltar2003@[EM  2008-03-27 09:27:48 
Re: How can I check if a file exists in gawk?
Ed Morton <morton@[EMA  2008-03-27 11:36:10 
Re: How can I check if a file exists in gawk?
Boltar <boltar2003@[EM  2008-03-27 09:48:25 
Re: How can I check if a file exists in gawk?
gazelle@[EMAIL PROTECTED]  2008-03-27 16:54:35 
Re: How can I check if a file exists in gawk?
Ed Morton <morton@[EMA  2008-03-27 12:00:41 
Re: How can I check if a file exists in gawk?
Michael Jaritz <ewigli  2008-03-27 23:36:22 
Re: How can I check if a file exists in gawk?
Ed Morton <morton@[EMA  2008-03-27 17:56:28 
Re: How can I check if a file exists in gawk?
stan <smoore@[EMAIL PR  2008-03-27 22:05:43 
Re: How can I check if a file exists in gawk?
Boltar <boltar2003@[EM  2008-03-27 10:04:11 
Re: How can I check if a file exists in gawk?
Ed Morton <morton@[EMA  2008-03-27 13:25:36 
Re: How can I check if a file exists in gawk?
mjc <mjcohen@[EMAIL PR  2008-03-29 13:12:23 
Re: How can I check if a file exists in gawk?
Ed Morton <morton@[EMA  2008-03-29 16:18:38 
Re: How can I check if a file exists in gawk?
mjc <mjcohen@[EMAIL PR  2008-03-30 08:22:43 
Re: How can I check if a file exists in gawk?
gazelle@[EMAIL PROTECTED]  2008-03-30 15:35:38 
Re: How can I check if a file exists in gawk?
Ed Morton <morton@[EMA  2008-03-30 13:30:10 
Re: How can I check if a file exists in gawk?
gazelle@[EMAIL PROTECTED]  2008-03-30 20:30:58 
Re: How can I check if a file exists in gawk?
Janis Papanagnou <Jani  2008-03-30 22:56:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 8:54:29 CDT 2008.