Score:0

Append to a variable in awk

jp flag

When using bash I can append to a variable with +=. I want to do something similar in awk. What can I use ?

  rl="?(+)*([$dgt])?([.,])+([$dgt])"
  rl+="?([eE]?([-+])+([$dgt]))"
Score:1
hr flag

String variables in awk are concatenated simply by writing them side-by-side. So:

rl="?(+)*([$dgt])?([.,])+([$dgt])"
rl = rl "?([eE]?([-+])+([$dgt]))"

(the intervening whitespace is optional).

See String Concatenation.


BTW if you are trying to pass a shell variable $dgt into your awk program, don't do it like that - use something like -v dgt="$dgt" on the command line and then rl = sprintf("?(+)*([%s])?([.,])+([%s])", dgt, dgt) to write it into the string. You could even consider using sprintf to do the concatenation:

rl = sprintf("?(+)*([%s])?([.,])+([%s])", dgt, dgt)
rl = sprintf("%s?([eE]?([-+])+([%s]))", rl, dgt)
Score:0
tn flag

Dunno what means your regex attempts, anyway try this:

$ awk '{var="foo"$1;print var}' <<< bar
foobar
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.