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 11 of 17 Topic 2207 of 2236
Post > Topic >>

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

by mjc <mjcohen@[EMAIL PROTECTED] > Mar 29, 2008 at 01:12 PM

On Mar 27, 8:05 pm, stan <smo...@[EMAIL PROTECTED]
> wrote:
> Ed Morton wrote:
>
> > On 3/27/2008 11:48 AM, Boltar wrote:
> >> On Mar 27, 4:36 pm, Ed Morton <mor...@[EMAIL PROTECTED]
> wrote:
>
> >>>On 3/27/2008 11:27 AM, Boltar wrote:
>
> <snip>
>
> >> but I guess that just another one of awks irritating little quirks.
>
> > It is not an awk quirk, it's one of the many getline features that
aren't
> > intuitively obvious and all of which need to be thoroughly understood
before
> > deciding whether or not to use getline.
>
> Personally, I found that I needed a firm fixed rule that every time I
> type getline I have to get up and go get a cup of coffee. Without any
> exceptions that I can remember I always find that I was trying to write
> a c progrm in awk and with a little reflection I can find a solution
> that uses awk instead of fighting against it.

I'm the reverse - I LIKE getline.

I have a utility subroutine for checking if a file exists:

function exists(file      , line)
{
   if ( (getline line < file) > 0 )
    {
      close(file);
      return 1;
    }
   else
    {
      return 0;
    }
}

I tend to use gawk as a general purpose programming language, so the
fact that it is C-like is a plus to me.

When the pattern-matching paradigm is appropriate, I use it; when it
isn't, I use getline to read from any number of files.

imho, the contortions needed to not use getline when reading multiple
files are less clear than using getline for all but one.

Please don't vote me off the island.

martin cohen




 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:55:17 CDT 2008.