Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • Is it equivalent to awk -F ',' -v OFS="," '{print $2, $3}' A.tsv Commented Jul 26, 2021 at 2:04
  • Or awk 'BEGIN{FS=OFS=","} ... '. Commented Jul 26, 2021 at 8:05
  • 4
    I know all the AWK documentation says "pattern" but it's all wrong. Awk is made up of <condition> { <action> } statements, not <pattern> { <action> } statements. The latter made some sense in the very first awk version which really only did pattern matching but is woefully misleading and outdated for any awk version since the 1980s. In what way is foo == 17 a pattern? It's not, it's a condition. In what way is TRUE a pattern? It's not, it's a condition. When we write if (X) <action> in C, we don't say X is a pattern, it's a condition. And so on... Commented Jul 26, 2021 at 21:50
  • 1
    @Porcupine no, awk '{print $2, $3}' FS="," OFS="," A.tsv is similar to awk -F ',' -v OFS="," '{print $2, $3}' A.tsv but it's not equivalent. They are different in when the assignments take effect (in BEGIN for -v, after it for arg list), and whether or not escape sequences get translated (they do for -v, they don't for arg list) and whether or not they are stored in ARGV and impact ARGC (they do not for -v, they do for arg list). Commented Jul 26, 2021 at 21:58
  • 1
    Some people refer to the whole <condition> { <action> } statement as a "rule" (we just saw such a reference on the bug-gawk mailing list IIRC), but for me "rule", like "pattern", is kinda vague and needs to be defined in any given context. You can't go wrong with saying <condition> { <action> } - that is 100% accurate and unambiguous. Commented Jul 26, 2021 at 22:01