質問

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

役に立ちましたか?

解決

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.

他のヒント

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top