original-mawk icon indicating copy to clipboard operation
original-mawk copied to clipboard

OFS doesn't act like a separator

Open Pyrrha opened this issue 2 years ago • 1 comments

Hello,

I'm using the awk command to increase a version number.

$ awk -vFS=. -vOFS=. '{$NF++;print}' <<< 1.2.99
1.2.100

However, when using the same command with mawk, I'm getting another behaviour.

$ mawk -vFS=. -vOFS=. '{$NF++;print}' <<< 1.2.99
1.2.99.

I think this is an issue with OFS, but maybe not only. Could also be the parsing, that doesn't catch the \n properly? What do you think?

Thanks

Pyrrha avatar Jan 02 '24 09:01 Pyrrha

There's more than one difference that I see, depending on the options used. Since awk (bwk) and gawk are giving the same result, it's something to investigate.

With neither FS or OFS, and changing the print to make it more apparent

  • $AWK '{$NF++;printf "{{%s}}", $0}' mawk: {{1.2.99 }} awk: {{2.2}}

  • $AWK -vFS=. '{$NF++;printf "{{%s}}", $0}' mawk: {{1 2 99 }} awk: {{1 2 100}}

  • $AWK -vFS=. -vOFS=: '{$NF++;printf "{{%s}}", $0}' mawk: {{1:2:99:}} awk: {{1:2:100}}

In the first example, I suppose that because the string does not look like a valid number, mawk ignores the increment. The second and third examples give the same result, so OFS appears irrelevant. Whether mawk should increment the last field -- that seems familiar (perhaps already reported difference). So I'll keep this open until I've had a chance to investigate those two differences.

ThomasDickey avatar Jan 08 '24 00:01 ThomasDickey