Commands in awk

huangapple go评论44阅读模式
英文:

Commands in awk

问题

awk文件中,需要在每个命令的末尾加上分号(;)吗?

title = gensub (beg_ere, "\", 1, $0);
subtitle = gensub (beg_ere, "\", 1, $0);
keywords = gensub (beg_ere, "\", 1, $0);

nu = split (ukeys, uaggr, ",");
nk = split (keywords, kaggr, ",");
英文:

Do I need to have ; at the end of each command in awk files.

  title = gensub (beg_ere, "\", 1, $0);
  subtitle = gensub (beg_ere, "\", 1, $0);
  keywords = gensub (beg_ere, "\", 1, $0);

  nu = split (ukeys, uaggr, ",");
  nk = split (keywords, kaggr, ",");

答案1

得分: 0

以下是已翻译的内容:

awk语法 包含以下定义:

program          : item_list
                 | item_list item
                 ;

item_list        : /* empty */
                 | item_list item terminator
                 ;

terminator       : terminator NEWLINE
                 |            ';'
                 |            NEWLINE
                 ;

因此,不,你并不总是需要分号。只有当你试图将两个项放在同一行时才需要分号(即没有换行符之间)。

英文:

The awk grammar contains the definitions:

program          : item_list
                 | item_list item
                 ;

item_list        : /* empty */
                 | item_list item terminator
                 ;

and

terminator       : terminator NEWLINE
                 |            ';'
                 |            NEWLINE
                 ;

So, no, you do not always need a semi-colon. Only if you are trying to put two items on the same line (ie. no newline in between).

答案2

得分: 0

在AWK文件中,每个命令的结尾是否需要分号?《AWK编程语言》关于操作(Actions)的部分提到:

有时,一个操作非常简单:只是一个单独的打印(print)或赋值(assignment)操作。其他时候,它可能是一系列由换行符或分号分隔的多个语句的序列。(...)

这意味着只使用换行或只使用分号来分隔操作是足够的。

英文:

> Do I need to have ; at the end of each command in awk files.

The AWK programming language says about Actions that

> Sometimes an action is very simple: a single print or assignment.
> Other times, it may be a sequence of several statements separated by
> newlines or semicolons.(...)

which means using only newline or only semicolon to separate is enough.

huangapple
  • 本文由 发表于 2023年2月6日 10:59:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75356975.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定