Handy way to id the end of file 
Author Message
 Handy way to id the end of file

Does awk have a handy way to notice it has reached the end of a file,
when multiple files are fed in?

Maybe by noticing the value of FILENAME changes...

Imagine you wanted to flag a group of lines that always start with a
known regexp and end at the end of the file.  Is there a handy regexp
operator that fits the end of file?



Mon, 06 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file

Quote:

> Does awk have a handy way to notice it has reached the end of a file,
> when multiple files are fed in?

No.

Quote:
> Maybe by noticing the value of FILENAME changes...

You, the programmer, can do this, but awk doesn't have a built-in
mechanism for detecting end-of-file. Though you cannot detect when
you're at the last line of a file, you can detect when you're at
the first line of the second and all subsequent files, and also
when you're at the end of all input files.

Two idioms come to mind that you may find useful:

  FNR == 1 && FNR != NR {
      # do end-of-file processing for first through second-to-last files
      # if there are multiple files
  }

  ...

  END {
      # do end-of-file processing for last file
  }

  --

  filename != FILENAME {
      if (filename) {
          # do end-of-file processing for first through second-to-last files
          # if there are multiple files
      }

      filename = FILENAME
  }

  ...

  END {
      # do end-of-file processing for last file, the name of which
      # is in the variable filename
  }

Quote:
> Imagine you wanted to flag a group of lines that always start with a
> known regexp and end at the end of the file. Is there a handy regexp
> operator that fits the end of file?

Something akin to sed's '$' last-line-of-input address operator?
Or Perl's 'eof' function? No.

You can easily accomplish the task you describe using one of the
above idioms.

--
Jim Monty

Tempe, Arizona USA



Mon, 06 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file


Quote:
> Does awk have a handy way to notice it has reached the end of a
> file, when multiple files are fed in?  Is there a handy regexp
> operator that fits the end of file?

Set up a function, and call it from the following "hooks" at the top
of your program:

{if ((FNR==1)&&(NR!=1)) {MyEOFroutine()}}
END{MyEOFroutine()}

... your program foes here ...

function MyEOFroutine() {... your end-of-file routine goes here}

--



Mon, 06 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file

Quote:


> > Does awk have a handy way to notice it has reached the end of a file,
> > when multiple files are fed in?

> No.

Too bad ..

[...]

Quote:
> Two idioms come to mind that you may find useful:

>   FNR == 1 && FNR != NR {
>       # do end-of-file processing for first through second-to-last files
>       # if there are multiple files
>   }

>   ...

>   END {
>       # do end-of-file processing for last file
>   }

I think I see how the one above works.. FNR is equal to 1 on the first
line of any file, but is NOT equal to NR only on the second file and
there after, so the processing occurs as the next file starts to be read.

Quote:
>   --

>   filename != FILENAME {
>       if (filename) {
>           # do end-of-file processing for first through second-to-last files
>           # if there are multiple files
>       }

>       filename = FILENAME
>   }

>   ...

>   END {
>       # do end-of-file processing for last file, the name of which
>       # is in the variable filename
>   }

This one seems a bit trickier.. not sure I follow here.

Either one can be worked into my code .. .. thanks.



Mon, 06 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file

Quote:


> > Does awk have a handy way to notice it has reached the end of a file,
> > when multiple files are fed in?

> No.

To bad

[...]

Quote:

> Two idioms come to mind that you may find useful:

>   FNR == 1 && FNR != NR {
>       # do end-of-file processing for first through second-to-last files
>       # if there are multiple files
>   }

>   ...

>   END {
>       # do end-of-file processing for last file
>   }

I think I follow the one above because FNR and NR will be the same
until the second file comes up then FNR will  go back to 1 causing the
processing to take place.

Quote:
>   --

>   filename != FILENAME {
>       if (filename) {
>           # do end-of-file processing for first through second-to-last files
>           # if there are multiple files
>       }

>       filename = FILENAME
>   }

>   ...

>   END {
>       # do end-of-file processing for last file, the name of which
>       # is in the variable filename
>   }

This one looks a bit trickier.  Not sure I follow this one.

I couldn't think of a better way to handle this situation without
making use of the end of the file.  But looking at it some more I
think it may not be necessary.  I've probably vastly overcomplicated
this.

My objective is to send awk on a retrieval mission into hundreds of
files that are mail messages stored in MH (one file per message) format.

When awk finds three REs I've selected, in a single file. I want to
print them out then go to the next file.  I'm using the REs to set
Variables that need to be zeroed out after the printing happens.

An example of what I'm trying to do might look like this:

  /^From:.*Putnam/ {from=$0;fr=1}
  /^Xref:.*ding2/ {xref=$0;xr=1}
  /\.fmt/ {a++;if (3 ==  a+fr+xr) ;print FILENAME,from"\n"
  FILENAME,xref"\n"FILENAME,$0"\n--"}
  FNR == 1 && FNR != NR {re1=re2=0}

Trying to increment `a' so that it only prints on the first occurrence
while it still all adds up to three.

I probably have the  syntax hopelessly butchered to boot.

I originally wanted to use the EOF to zero out the variables for the
next go around.  But that isn't good enough.  Some how  the script
above prints out all three things every time the firt 2 RE are satisfied
and the 3rd one shows up.  So that in some files It may all be printed
several times.

A real example of the output is what I was after but I want to limit
it to one printing per file.  So that only the first occurence of RE3
invokes the printing:


/home/reader/tmp2/2806 Xref: reader.ptw.com ding2:2806
/home/reader/tmp2/2806 2) Using the example *.fmt file from
nnir-1.57.el  and giving it the title mail.fmt.
--

In some files that contain several occurences of `.fmt' the whole mess
gets printed repeatedly with only the 3rd line different.

I tried just zeroing out `fr' and `xr' right after printing like this:
[...]
/\.fmt/ {a++;if (3 ==  a+fr+xr) ;print FILENAME,from"\n" FILENAME,xref"\n"\
FILENAME,$0"\n--"}
fr=xr=0

But still the multiple prints occur.  Tossing a `next' in there
doesn't cure it either:

[...]
/\.fmt/ {a++;if (3 ==  a+fr+xr) ;print FILENAME,from"\n" FILENAME,xref"\n"\
FILENAME,$0"\n--";next}
[...]

Also trying to keep an eye toward making this easy to change the REs
but failling on that so far too.



Mon, 06 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file


% An example of what I'm trying to do might look like this:
%
%   /^From:.*Putnam/ {from=$0;fr=1}
%   /^Xref:.*ding2/ {xref=$0;xr=1}
%   /\.fmt/ {a++;if (3 ==  a+fr+xr) ;print FILENAME,from"\n" FILENAME,xref"\n"FILENAME,$0"\n--"}
                                    ^ this semi-colon is bad

%  
%   FNR == 1 && FNR != NR {re1=re2=0}

What your if statement says is

 if 3 == a+fr+xr then do nothing
 print FILENAME, from

Although I'm normally all in favour of slightly cryptic code, in this
case you might want to try a simpler test (unless you need the value
of a for something else). For instance, you could make the test
 /\.fmt/ && fr && xr { print FILENAME, from "\n" FILENAME,xref"\n"FILENAME,$0"\n--"
                       xr = fr = 0 }
and get rid of the test for end of file, altogether.

% I tried just zeroing out `fr' and `xr' right after printing like this:
% [...]
% /\.fmt/ {a++;if (3 ==  a+fr+xr) ;print FILENAME,from"\n" FILENAME,xref"\n"\
% FILENAME,$0"\n--"}
% fr=xr=0

OK, so you thought of this. The problem with your attempt (apart from the
; after the if statement) is that fr = xr = 0 will be executed for
every line of input, so neither will be 1 for more than a fleeting
instant.
--

Patrick TJ McPhee
East York  Canada



Tue, 07 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file


Quote:


>> Does awk have a handy way to notice it has reached the end of a
>> file, when multiple files are fed in?  Is there a handy regexp
>> operator that fits the end of file?

>Set up a function, and call it from the following "hooks" at the top
>of your program:

>{if ((FNR==1)&&(NR!=1)) {MyEOFroutine()}}
>END{MyEOFroutine()}

>... your program goes here ...

>function MyEOFroutine() {... your end-of-file routine goes here}

A trick you may want to consider that eliminates the last END {....}
bit of code, is to include at the end of the FILE-LIST a null file
ie  awk -f awkprog file1 file2 .... filen  nullfile

Not sure which is 'better', but I prefer to use this technique ;-)

Mark
---
Mark Katz
Mark-it, London. Delivering MR-IT/Internet solutions
Tel: (44) 20-8731 7516, Fax: (44) 20-8458 9554
For latest information about ISPC/ITE - see http://www.e-tabs.com



Tue, 07 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file

Quote:

> I couldn't think of a better way to handle this situation without
> making use of the end of the file. But looking at it some more I
> think it may not be necessary. I've probably vastly overcomplicated
> this.

Not "vastly" overcomplicated, but you are making a simple problem
difficult.

Quote:
> My objective is to send awk on a retrieval mission into hundreds of
> files that are mail messages stored in MH (one file per message) format.

> When awk finds three REs I've selected, in a single file. I want to
> print them out then go to the next file. I'm using the REs to set
> Variables that need to be zeroed out after the printing happens.

> An example of what I'm trying to do might look like this:

>   /^From:.*Putnam/ {from=$0;fr=1}
>   /^Xref:.*ding2/ {xref=$0;xr=1}
>   /\.fmt/ {a++;if (3 ==  a+fr+xr) ;print FILENAME,from"\n"
>   FILENAME,xref"\n"FILENAME,$0"\n--"}
>   FNR == 1 && FNR != NR {re1=re2=0}

<snip>

Quote:
> A real example of the output is what I was after but I want to limit
> it to one printing per file. So that only the first occurence of RE3
> invokes the printing:


> /home/reader/tmp2/2806 Xref: reader.ptw.com ding2:2806
> /home/reader/tmp2/2806 2) Using the example *.fmt file from
> nnir-1.57.el  and giving it the title mail.fmt.
> --

<snip>

Quote:
> Also trying to keep an eye toward making this easy to change the REs
> but failling on that so far too.

You simply need to initialize the variables at the beginning of
each file (i.e., when FNR == 1), and exploit the Boolean value of
the variable that contains the line matching the third regular
expression pattern. The following script is untested:

#!/usr/bin/awk -f

BEGIN {
    from_pattern = "^From:.*Putnam"
    xref_pattern = "^Xref:.*ding2"
    file_pattern = "\.fmt"

Quote:
}

{
    # initialize variables at the beginning of each file
    if (FNR == 1) {
        from = ""
        xref = ""
        file = ""  # variable named file is now FALSE
    }

    if ($0 ~ from_pattern) {
        from = $0
    } else if ($0 ~ xref_pattern) {
        xref = $0
    } else if ($0 ~ file_pattern && ! file) {
        # now at first occurrence of file_pattern in current file

        file = $0  # variable named file is now TRUE

        print FILENAME, from
        print FILENAME, xref
        print FILENAME, file
        print "-- "
    }

Quote:
}

Note that a record is printed regardless of whether either from_pattern
or xref_pattern were previously matched. If this is incorrect, then
simply add the appropriate tests to the compound conditional expression.
For example:

    ... } else if ($0 ~ file_pattern && from && xref && ! file) { ...

HTH.

--
Jim Monty

Tempe, Arizona USA



Tue, 07 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file

...

Quote:
>>{if ((FNR==1)&&(NR!=1)) {MyEOFroutine()}}
>>END{MyEOFroutine()}

>>... your program goes here ...

>>function MyEOFroutine() {... your end-of-file routine goes here}

>A trick you may want to consider that eliminates the last END {....}
>bit of code, is to include at the end of the FILE-LIST a null file
>ie  awk -f awkprog file1 file2 .... filen  nullfile

>Not sure which is 'better', but I prefer to use this technique ;-)

Of course, since *you* use Thompson AWK (smart, very smart!), you should be
using BEGINFILE and ENDFILE.


Tue, 07 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file

[...]

Quote:
> %   /\.fmt/ {a++;if (3 ==  a+fr+xr) ;print FILENAME,from"\n" FILENAME,xref"\n"FILENAME,$0"\n--"}
>                                     ^ this semi-colon is bad
> %   FNR == 1 && FNR != NR {re1=re2=0}

> What your if statement says is

>  if 3 == a+fr+xr then do nothing
>  print FILENAME, from

> Although I'm normally all in favour of slightly cryptic code, in this
> case you might want to try a simpler test (unless you need the value
> of a for something else). For instance, you could make the test
>  /\.fmt/ && fr && xr { print FILENAME, from "\n" FILENAME,xref"\n"FILENAME,$0"\n--"
>                        xr = fr = 0 }
> and get rid of the test for end of file, altogether.

What I've done in addition to get some sleep is post in a new thread
since I'd made enough typos, sloppy pastes and untoward posts to ward
of even the hardiest reader.

I really appreciate your staying power/

Quote:
> % fr=xr=0

> OK, so you thought of this. The problem with your attempt (apart from the
> ; after the if statement) is that fr = xr = 0 will be executed for
> every line of input, so neither will be 1 for more than a fleeting
> instant.

So thats why that never worked ... duh..

If you feel up to it, please look at the new thread.
Subject: Trial and error...

Some of this has gotten cleaned up and is mostly working now.



Tue, 07 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file

Quote:

> A trick you may want to consider that eliminates the last END {....}
> bit of code, is to include at the end of the FILE-LIST a null file
> ie  awk -f awkprog file1 file2 .... filen  nullfile

> Not sure which is 'better', but I prefer to use this technique ;-)

Another cool trick I never thought of....


Tue, 07 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file

[...]

Jim,  I've (probably ill-advisedly) moved this discussion to a new
thread (Subject: Trial and error..) Thinking I had posted so many
errors etc as to make things unduly complicated.  But I see you've
persevered and offered more good advice.

Your program below does nicely do what I laid out but leaves a few
things open that have come up.  Examples and further comments below
your script.

Quote:

> You simply need to initialize the variables at the beginning of
> each file (i.e., when FNR == 1), and exploit the Boolean value of
> the variable that contains the line matching the third regular
> expression pattern. The following script is untested:

> #!/usr/bin/awk -f

> BEGIN {
>     from_pattern = "^From:.*Putnam"
>     xref_pattern = "^Xref:.*ding2"
>     file_pattern = "\.fmt"
> }

> {
>     # initialize variables at the beginning of each file
>     if (FNR == 1) {
>         from = ""
>         xref = ""
>         file = ""  # variable named file is now FALSE
>     }

>     if ($0 ~ from_pattern) {
>         from = $0
>     } else if ($0 ~ xref_pattern) {
>         xref = $0
>     } else if ($0 ~ file_pattern && ! file) {
>         # now at first occurrence of file_pattern in current file

>         file = $0  # variable named file is now TRUE

>         print FILENAME, from
>         print FILENAME, xref
>         print FILENAME, file
>         print "-- "
>     }
> }

> Note that a record is printed regardless of whether either from_pattern
> or xref_pattern were previously matched. If this is incorrect, then
> simply add the appropriate tests to the compound conditional expression.
> For example:

That would be wrong behavior in this case so incorporating your extra
code below

Quote:
>     ... } else if ($0 ~ file_pattern && from && xref && ! file) { ...

This works to a point and does all I asked, but my expectations have
changed.

Now I want to prevent false hits from possible header like lines that
may be incuded in the body of messages and to print all the
occurrences of the final RE (file_pattern) as long as the first 2 are
satisfied.

In a similar vein as in the new thread, I've butchered up your nice
syntax and added some increment operators to handle the problem
described. (False hits ) and `cooked' up an input file with an
/^Xref:.*ding2/ line that looks like:

(In the body)

Sure enough since the `cooked' line appears last it is printed instead
of the right one, with your unchanged script.

Hacked version:
BEGIN {
    from_pattern = "^From:.*Putnam"
    xref_pattern = "^Xref:.*ding2"
    file_pattern = "\.fmt"

Quote:
}

{
    # initialize variables at the beginning of each file
    if (FNR == 1) {
        from = ""
        xref = ""
         a=b = 0    
        file = ""  # variable named file is now FALSE
    }

    if ($0 ~ from_pattern) {
        from = $0 ; a++
    } else if ($0 ~ xref_pattern) {
        xref = $0 ; b++
    } else if ($0 ~ file_pattern &&  ! file && 2 == a+b ) {
        # now at first occurrence of file_pattern in current file

        file = $0  # variable named file is now TRUE

        print FILENAME, from
        print FILENAME, xref
        print FILENAME, file
        print "-- "
    }

Quote:
}

With this approach I'm not sure how to cause more than one occurrence
of /\.fmt/ to be printed along with the other output.


Tue, 07 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file

Quote:


> > #!/usr/bin/awk -f

> > BEGIN {
> >     from_pattern = "^From:.*Putnam"
> >     xref_pattern = "^Xref:.*ding2"
> >     file_pattern = "\.fmt"
> > }

> > {
> >     # initialize variables at the beginning of each file
> >     if (FNR == 1) {
> >         from = ""
> >         xref = ""
> >         file = ""  # variable named file is now FALSE
> >     }

> >     if ($0 ~ from_pattern) {
> >         from = $0
> >     } else if ($0 ~ xref_pattern) {
> >         xref = $0
> >     } else if ($0 ~ file_pattern && ! file) {
> >         # now at first occurrence of file_pattern in current file

> >         file = $0  # variable named file is now TRUE

> >         print FILENAME, from
> >         print FILENAME, xref
> >         print FILENAME, file
> >         print "-- "
> >     }
> > }

> > Note that a record is printed regardless of whether either from_pattern
> > or xref_pattern were previously matched. If this is incorrect, then
> > simply add the appropriate tests to the compound conditional expression.
> > For example:

> That would be wrong behavior in this case so incorporating your extra
> code below

> >     ... } else if ($0 ~ file_pattern && from && xref && ! file) { ...

> This works to a point and does all I asked, but my expectations have
> changed.

A well-written program easily adapts to modest changes in its
specification.

Quote:
> Now I want to prevent false hits from possible header like lines that
> may be incuded in the body of messages ...

This implies that you MUST have some positive means by which you
can know whether the text you are matching is within the header
section or not. In other words, the message file format must at
least be defined well enough such that it can readily be parsed
into headers and bodies. This is certainly true of RFC 822-compliant
messages and, consequently, MH messages: the header lines are
separated from the message body by a blank line.

Since MH messages are separated into individual files, the rule is
simple: the headers lines are those at the top of the file that
precede the first blank line, and the message body is everything
in the file beneath the first blank line. So implementing a
header-body state machine in awk is trivial:

    if (FNR == 1) {
        in_header = 1
    } else if (in_header && /^$/) {
        in_header = 0
    }

[N.B. I make no claim that any of my statements about the MH message
format are strictly correct. I don't use MH and I'm only casually
familiar with the RFC 822 specification. Read the documentation.]

Quote:
> ... and to print all the occurrences of the final RE (file_pattern)
> as long as the first 2 are satisfied.

Do you mean "print all the occurrences of lines within the message
body that match some regular expression pattern (file_pattern)
within any message in which two other regular expression patterns
(from_pattern and xref_pattern) are matched by lines in the header
section"? It seems there are two levels of matching: match a message,
and then, within that matched message, match lines. Is this correct?

The following script is untested and is intended only to demonstrate
a possible approach to solving your problem:

#!/usr/bin/awk -f

BEGIN {
    from_pattern = "^From:.*Putnam"
    xref_pattern = "^Xref:.*ding2"
    file_pattern = "\.fmt"

Quote:
}

{
    if (FNR == 1) {
        in_header  = 1
        in_matched = 0
        from_line  = ""
        xref_line  = ""
        file_line  = ""
    } else if (in_header && /^$/) {
        in_header  = 0
        if (from_line && xref_line) {
            in_matched = 1
        }
    }

    if (in_header) {  # in header section
        if ($0 ~ from_pattern) {
            from_line = $0
        } else if ($0 ~ xref_pattern) {
            xref_line = $0
        }
    } else if (in_matched) {  # in body of matched message
        if ($0 ~ file_pattern) {
            if (! file_line) {
                print FILENAME, from_line
                print FILENAME, xref_line
            }
            file_line = $0
            print FILENAME, file_line
        }
    } else {  # in body of unmatched message
        # nextfile  # GNU awk extension to skip to next file
    }

Quote:
}

You should be able to follow the logic of this simple state machine.
Notice the lack of any arithmetic operations (e.g., incrementation).
What is there to count? This program is about state, not math.

Printing a trailing record terminator token ("-- ") is simply a
matter of testing the status of the previous message each time you
read a new file and at the end of all input. I've already posted
examples of idioms to do just that.

--
Jim Monty

Tempe, Arizona USA



Wed, 08 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file
[...]

Quote:
> Do you mean "print all the occurrences of lines within the message
> body that match some regular expression pattern (file_pattern)
> within any message in which two other regular expression patterns
> (from_pattern and xref_pattern) are matched by lines in the header
> section"? It seems there are two levels of matching: match a message,
> and then, within that matched message, match lines. Is this correct?

Yes, that is what I meant.

Quote:

> The following script is untested and is intended only to demonstrate
> a possible approach to solving your problem:

> #!/usr/bin/awk -f

> BEGIN {
>     from_pattern = "^From:.*Putnam"
>     xref_pattern = "^Xref:.*ding2"
>     file_pattern = "\.fmt"
> }

> {
>     if (FNR == 1) {
>         in_header  = 1
>         in_matched = 0
>         from_line  = ""
>         xref_line  = ""
>         file_line  = ""
>     } else if (in_header && /^$/) {
>         in_header  = 0
>         if (from_line && xref_line) {
>             in_matched = 1
>         }
>     }

>     if (in_header) {  # in header section
>         if ($0 ~ from_pattern) {
>             from_line = $0
>         } else if ($0 ~ xref_pattern) {
>             xref_line = $0
>         }
>     } else if (in_matched) {  # in body of matched message
>         if ($0 ~ file_pattern) {
>             if (! file_line) {
>                 print FILENAME, from_line
>                 print FILENAME, xref_line
>             }
>             file_line = $0
>             print FILENAME, file_line
>         }
>     } else {  # in body of unmatched message
>         # nextfile  # GNU awk extension to skip to next file
>     }
> }

> You should be able to follow the logic of this simple state machine.
> Notice the lack of any arithmetic operations (e.g., incrementation).
> What is there to count? This program is about state, not math.

Yes I am able to follow the logic but keep stumbling over the
`file_line' entry.  Its set to `null' in the beginning right? or does
that just mean empty?

I was confused about it in the previous rendition too.

Not sure I understand what it does at its next appearance.  I'm
probably reading the syntax wrong but it appears to be something like:

If in body section of a `matched' message  and
If a line matches the RE contained in `file_pattern'  and
If not null (or empty)  <== here is where I get confused.

If what is not null?  $0?  But the match against the RE means it is
not.

Or does the ! operator mean something besides `not' in this usage?
My Gawk info pages indicates it means simpley `not'.

With that little confusion aside this script looks like a beautiful
piece of work. It easily handles several possible states.  Something I
was having plenty of trouble with.  But beginning to see how it is
done, and looks like it would have plenty of other applications.

I'm trying this out now so want to give it a good work out, maybe I'll
see exactly what it does by usage.



Wed, 08 Jan 2003 03:00:00 GMT  
 Handy way to id the end of file

Quote:

> You, the programmer, can do this, but awk doesn't have a built-in
> mechanism for detecting end-of-file. Though you cannot detect when
> you're at the last line of a file, you can detect when you're at
> the first line of the second and all subsequent files, and also
> when you're at the end of all input files.

> Two idioms come to mind that you may find useful:

[...]

Quote:

>   filename != FILENAME {
>       if (filename) {
>           # do end-of-file processing for first through second-to-last files
>           # if there are multiple files
>       }

>       filename = FILENAME
>   }

>   ...

>   END {
>       # do end-of-file processing for last file, the name of which
>       # is in the variable filename
>   }

Jim, This one is torturing me..  Can't get my brain around this.

Lowercase `filename' is just an introduced variable right?  Not a builtin
like FILENAME that has an actual value at all times.

What I see here as a non-awk-adept is something like this:
Assuming we're in the first file

Out of the blue:

filename != FILENAME

FILENAME actually has a value   lets say its 6 and will soon be 7.

So then, coming to the if clause.

if (filename)  If filename what? if it is != FILENAME.  Why would that
signal the end of the file?  Couldn't `filename '!= FILENAME at the
beginning of the file as well?

Then we change the value of `filename' so that it equals FILENAME.
That remains true until a new file is opened.  Now in the second file
`filename' will not equal FILENAME from the begining.  So processing
could happen at any time until `filename' is made to equal FILENAME.

So with the second file `filename' is already !=FILENAME, why do we
need to explicitly give it the value !=FILENAME?



Wed, 08 Jan 2003 03:00:00 GMT  
 
 [ 17 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Handy way to id the end of file [revisited]

2. Handy Tools Page Announces Handy Tools for Clarion Windows

3. end-of-record versus end-of-file?

4. select to id end - one char missing

5. end of file for large files

6. NEWBIE TIP: Reading a file two different ways...from ENGSOL

7. Different ways to read in a file

8. select count(*) from test_file where id>100 and id<1000

9. Object IDs are good ( was: Object IDs are bad )

10. Testing if ID is a VALID TSO ID

11. expect_after executes for spawn id 1 even if the corresponding expect executes for spawn id 2

12. Clarion 2.1 DOS - Owner ID on DAT file

 

 
Powered by phpBB® Forum Software