help-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rule with starting { on next line


From: Neil R. Ormos
Subject: Re: Rule with starting { on next line
Date: Sun, 9 Apr 2023 20:02:54 -0500 (CDT)
User-agent: Alpine 2.20 (DEB 67 2015-01-07)

uzibalqa via Help-gawk wrote:

> I am doing the following, which is repeating
> "MATCH $0 BEG_ERE" for every line.  Primarily
> because the starting "{" starts on the next
> line.  Would this be a bug?

> match($0, beg_ere, maggr)
>  {
>   print "MATCH $0 BEG_ERE"
>   print "   " $0
>   next
>  }

No. That's not a bug in gawk.  The manual states:

| 1.6 awk Statements Versus Lines

| [...]
| awk is a line-oriented language. Each rule's
| action has to begin on the same line as the
| pattern. To have the pattern and action on
| separate lines, you must use backslash
| continuation; there is no other option. [1]

AND

| 1.3 Some Simple Examples

| [...]
| In an awk rule, either the pattern or the action
| can be omitted, but not both. If the pattern is
| omitted, then the action is performed for every
| input line. If the action is omitted, the
| default action is to print all lines that match
| the pattern.  [2]

In your program, the match() line has an empty action, which causes the default 
action, equivalent to

  print $0

to be executed for each line.

And then the { ... } is an action with an empty pattern, which matches all 
input lines.

=====

[1] <https://www.gnu.org/software/gawk/manual/gawk.html#Statements_002fLines>

[2] <https://www.gnu.org/software/gawk/manual/gawk.html#Very-Simple>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]