6

I would like to awk concatenate string variable in awk. How can I do that? I tried:

BEGIN{
t="."
r=";"
w=t+r
print w}

But I does't work. Output:

0

Or I want to add variable and result of function. Input:

t t t t
a t a ta
ata ta a a

Script:

{
key="t"
print gsub(key,"")#<-it's work
b=b+gsub(key,"")#<- it's something wrong
}
END{
print b}#<-so this is 0

Output:

4
2
2
0#<-the last print
diego9403
  • 897
  • 1
  • 12
  • 21
  • With `t+r` you implicitly cast both variables to numbers, and both become zero. Strings resembling numbers are converted to numbers: `t="1";r="2";w=t+r;print w` prints `3`. – simlev Apr 12 '18 at 13:01

1 Answers1

11

No operator is needed (or used). Your example would be something like

BEGIN{
t="."
r=";"
w=t r
print w}

For related discussion

Thomas Dickey
  • 8,632
  • 3
  • 22
  • 31