• what operation is $1.$2 ?

    From Ralf Fassel@ralfixx@gmx.de to comp.lang.awk on Wed Mar 9 20:29:22 2022
    From Newsgroup: comp.lang.awk

    GNU Awk 4.2.1, API: 2.0

    I wanted to run

    awk '{print $1 "." $2}'

    i.e. add a dot between $1 and $2, but accidentially typed

    awk '{print $1.$2}'

    which simply concatenates $1$2:

    echo 1 2 | awk '{print $1.$2}'
    12

    I wonder what operation is $1.$2, or why is awk not bailing out with a
    syntax error on this, like in:

    echo 1 2 | awk '{print $1 . $2}'
    awk: cmd. line:1: {print $1 . $2}
    awk: cmd. line:1: ^ syntax error


    TNX
    R'
    --- Synchronet 3.19c-Linux NewsLink 1.113
  • From Neil@nddtwentyone@gmail.com to comp.lang.awk on Wed Mar 9 19:48:54 2022
    From Newsgroup: comp.lang.awk

    Ralf Fassel <ralfixx@gmx.de> wrote:
    GNU Awk 4.2.1, API: 2.0

    I wanted to run

    awk '{print $1 "." $2}'

    i.e. add a dot between $1 and $2, but accidentially typed

    awk '{print $1.$2}'

    which simply concatenates $1$2:

    echo 1 2 | awk '{print $1.$2}'
    12

    I wonder what operation is $1.$2, or why is awk not bailing out with a
    syntax error on this, like in:

    echo 1 2 | awk '{print $1 . $2}'
    awk: cmd. line:1: {print $1 . $2}
    awk: cmd. line:1: ^ syntax error


    TNX
    R'

    I think $1. is the same as $1 (which is also the same as $1.234 ).
    --- Synchronet 3.19c-Linux NewsLink 1.113
  • From Janis Papanagnou@janis_papanagnou@hotmail.com to comp.lang.awk on Wed Mar 9 22:02:58 2022
    From Newsgroup: comp.lang.awk

    On 09.03.2022 20:29, Ralf Fassel wrote:
    GNU Awk 4.2.1, API: 2.0

    I wanted to run

    awk '{print $1 "." $2}'

    i.e. add a dot between $1 and $2, but accidentially typed

    awk '{print $1.$2}'

    which simply concatenates $1$2:

    echo 1 2 | awk '{print $1.$2}'
    12

    I wonder what operation is $1.$2,

    It's parsed as four components: $ 1. $ 2
    i.e. two field selector operators ($) and two numbers (1. and 2).

    Janis


    or why is awk not bailing out with a
    syntax error on this, like in:

    echo 1 2 | awk '{print $1 . $2}'
    awk: cmd. line:1: {print $1 . $2}
    awk: cmd. line:1: ^ syntax error


    TNX
    R'


    --- Synchronet 3.19c-Linux NewsLink 1.113
  • From J Naman@jnaman2@gmail.com to comp.lang.awk on Wed Mar 9 17:25:06 2022
    From Newsgroup: comp.lang.awk

    On Wednesday, 9 March 2022 at 16:02:59 UTC-5, Janis Papanagnou wrote:
    On 09.03.2022 20:29, Ralf Fassel wrote:
    GNU Awk 4.2.1, API: 2.0

    I wanted to run

    awk '{print $1 "." $2}'

    i.e. add a dot between $1 and $2, but accidentially typed

    awk '{print $1.$2}'

    which simply concatenates $1$2:

    echo 1 2 | awk '{print $1.$2}'
    12

    I wonder what operation is $1.$2,
    It's parsed as four components: $ 1. $ 2
    i.e. two field selector operators ($) and two numbers (1. and 2).

    Janis
    or why is awk not bailing out with a
    syntax error on this, like in:

    echo 1 2 | awk '{print $1 . $2}'
    awk: cmd. line:1: {print $1 . $2}
    awk: cmd. line:1: ^ syntax error


    TNX
    R'

    Try echo 3 4 | gawk "{print $1.$2}" => 34 ( no 1's or 2's)
    Try echo 3 4 | gawk "{print $1xyz$2}" => 34 (no xyz either)
    echo 3 4 | gawk "{print $1.xyz$2}"=> 34 (no xyz either)
    echo 3 4 | gawk "{print $1..$2}" two or more decimals gets syntax error
    See: converting string to numeric ignores alpha, but not 1.., that's syntax
    echo 123usd 456euro | gawk "{print $1+$2}" => 576
    ref: UsrGuide 6.1.4 Conversion of Strings and Numbers
    --- Synchronet 3.19c-Linux NewsLink 1.113
  • From Janis Papanagnou@janis_papanagnou@hotmail.com to comp.lang.awk on Thu Mar 10 05:51:29 2022
    From Newsgroup: comp.lang.awk

    On 10.03.2022 02:25, J Naman wrote:
    On Wednesday, 9 March 2022 at 16:02:59 UTC-5, Janis Papanagnou wrote:
    On 09.03.2022 20:29, Ralf Fassel wrote:
    GNU Awk 4.2.1, API: 2.0

    I wanted to run

    awk '{print $1 "." $2}'

    i.e. add a dot between $1 and $2, but accidentially typed

    awk '{print $1.$2}'

    which simply concatenates $1$2:

    echo 1 2 | awk '{print $1.$2}'
    12

    I wonder what operation is $1.$2,
    It's parsed as four components: $ 1. $ 2
    i.e. two field selector operators ($) and two numbers (1. and 2).

    Janis
    or why is awk not bailing out with a
    syntax error on this, like in:

    echo 1 2 | awk '{print $1 . $2}'
    awk: cmd. line:1: {print $1 . $2}
    awk: cmd. line:1: ^ syntax error


    TNX
    R'


    Which OS and shell did you use to execute the subsequent commands?

    On Unix systems the awk program argument should be quoted by single
    quotes

    awk '...'

    otherwise $var and $0 are expanded by the shell as shell variables
    and awk sees those instead of the passed in parameters.


    Try echo 3 4 | gawk "{print $1.$2}" => 34 ( no 1's or 2's)

    Of course no 1s or 2s, because $1. identifies the 1st field and $2
    identifies the second field.

    Try echo 3 4 | gawk "{print $1xyz$2}" => 34 (no xyz either)

    Of course no xyz, because you concatenate field one, variable xyz,
    and field 2, and variable xyz is undefined and thus empty. Define
    that variable and you'll see it

    $ echo 3 4 | gawk -v xyz=hoho '{print $1xyz$2}'
    3hoho4

    echo 3 4 | gawk "{print $1.xyz$2}"=> 34 (no xyz either)

    Of course not. Same reason like before.

    echo 3 4 | gawk "{print $1..$2}" two or more decimals gets syntax error

    Of course. While 1 and 1. are syntactic correct numbers, 1.. is not.

    See: converting string to numeric ignores alpha, but not 1.., that's syntax
    echo 123usd 456euro | gawk "{print $1+$2}" => 576

    Hardly correct. It must result in 579.

    The context is arithmetic so from the input fields only the numbers
    are taken.

    ref: UsrGuide 6.1.4 Conversion of Strings and Numbers

    And what was the point of your post as a reply to our posts?

    Janis

    --- Synchronet 3.19c-Linux NewsLink 1.113
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.awk on Thu Mar 10 10:50:44 2022
    From Newsgroup: comp.lang.awk

    * Janis Papanagnou <janis_papanagnou@hotmail.com>
    | > I wonder what operation is $1.$2,

    | It's parsed as four components: $ 1. $ 2
    | i.e. two field selector operators ($) and two numbers (1. and 2).

    Ouch (i.e. I understand :-)

    echo 1st 2nd | awk '{print $1.9}'
    1st

    echo 1st 2nd | awk '{print $1.9999999999999999999999999999999999}'
    2nd

    Thanks for the enlightment!
    R'
    --- Synchronet 3.19c-Linux NewsLink 1.113
  • From Kpop 2GM@jason.cy.kwan@gmail.com to comp.lang.awk on Mon Mar 28 11:53:09 2022
    From Newsgroup: comp.lang.awk

    i don't think it's an operation per se
    i *think* awk sees your thing as
    echo 1 2 | awk '{print $1.$2}'
    ——> awk '{print ($(1.))($2) }'
    ——> awk '{print ($(1.0))($2) }'
    ——> awk '{print ($1)($2) }'
    which is a delimiter-less string concat. I'm only guessing here
    The 4Chan Teller
    --- Synchronet 3.19c-Linux NewsLink 1.113