break? 
Author Message
 break?

well, here goes...
awk runs the script on each and every record.  i was wondering if
there's a way to make it (when some condition is satisfied) stop and
re-run the program again over the same file (i.e., like C's break
command).  i was thinking of something along the following lines:

BEGIN { flag=1; }
if (($0 ~ /pattern/) && (flag)) { do something useful};
if (($0 ~ /pattern/) && (!flag)) { do something very useful};
if(some_condition_or_pattern_match) { flag=0;
        break;  # here, i'd like the program to run over the file
                # again, but this time with flag=0
        }

of course, i could bypass it using some batch files, but what i really
want to know is whether there's such an awk command.




Sat, 25 Mar 2000 03:00:00 GMT  
 break?

well, here goes...
awk runs the script on each and every record.  i was wondering if
there's a way to make it (when some condition is satisfied) stop and
re-run the program again over the same file (i.e., like C's break
command).  i was thinking of something along the following lines:

BEGIN { flag=1; }
if (($0 ~ /pattern/) && (flag)) { do something useful};
if (($0 ~ /pattern/) && (!flag)) { do something very useful};
if(some_condition_or_pattern_match) { flag=0;
        break;  # here, i'd like the program to run over the file
                # again, but this time with flag=0
        }

of course, i could bypass it using some batch files, but what i really
want to know is whether there's such an awk command.




Sat, 25 Mar 2000 03:00:00 GMT  
 break?

Quote:

>well, here goes...
>awk runs the script on each and every record.  i was wondering if
>there's a way to make it (when some condition is satisfied) stop and
>re-run the program again over the same file (i.e., like C's break
>command).  i was thinking of something along the following lines:

>BEGIN { flag=1; }
>if (($0 ~ /pattern/) && (flag)) { do something useful};
>if (($0 ~ /pattern/) && (!flag)) { do something very useful};
>if(some_condition_or_pattern_match) { flag=0;
>    break;  # here, i'd like the program to run over the file
>            # again, but this time with flag=0
>    }

>of course, i could bypass it using some batch files, but what i really
>want to know is whether there's such an awk command.



There's nothing as simple as a "rewind" command which sounds like what
you're seeking.

You can of course pass AWK the file name several times, or if it is a
reasonably sized file you can read it completely into memory and then
access the RAM-based lines as many times as you like. And I suppose
you could write the input to another file and then process it.

The first will work if the file exists permanently; I believe you'll
be forced to the second method if the file is being piped to AWK. (I
use MS-DOS and TAWK; perhaps the UNIX wizards know of a way to better
handle piped input).

In the first method you'll have to process all the lines in first file
anyway, skipping them once you've set your 'flag'. And you'll have to
figure out by reading FNR what pass of the file you are processing.

In the second method, you'll give up some of the infrastructure that
AWK provides for pattern matching (like "pattern {process}") and
replicate that with calls to the match() function -- inside your own
for() loops that scan through the RAM-based lines.

DKM



Sun, 26 Mar 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Handling group breaks and page breaks run time

2. CPCS - Page Break on Control Break?

3. Is break broken? :) :) :)

4. C5B ABC Report -- How to "page break" in a group break

5. Report Feature--Nested Breaks

6. Wiki index is broken

7. J tutorials were broken by j 4.0

8. CONTINUE and BREAK support for HLASM SP macros

9. Is String>>sprintfWith: broken?

10. System Transcript Window broken

11. break into Smalltalk?

12. 4.01 downloads page broken?

 

 
Powered by phpBB® Forum Software