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