Domanda

i want to concatenate three variable output to one variable inside a awk script in print statement. ex: a="a" b="b" c="c" and expected output is d=a-b-c

È stato utile?

Soluzione

You don't say if the three variables are awk variables or shell variables so assuming they are awk variables:

$ awk 'BEGIN {
    a = "a"
    b = "b"
    c = "c"
    print "d=" a "-" b "-" c
}'
d=a-b-c

If they are shell variables, see @Jotne's answer.

Altri suggerimenti

Here is how to do it:

a=a
b=b
c=c
d=$(awk -v x="$a" -v y="$b" -v z="$c" -v OFS="-" 'BEGIN {print x,y,z}')
echo $d
a-b-c

You declare variable in awk, by using the -v option.


Or to print it, if that is what you need

awk -v x="$a" -v y="$b" -v z="$c" -v OFS="-" 'BEGIN {print "d="x,y,z}'
d=a-b-c
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top