我想在变量“dc”中列出字段,例如“$1,$2”。该变量被传递给 awk,但没有像我预期的那样工作。
$ dc='$1, $2' # variable with list of fields
$ fff="%-3s %-3s\n" # format
$ echo "1 2 3 4 5"|awk -v fff="$fff" -v dc="$dc" '{printf fff, $1, $2}' ### OK
1 2
$ echo "1 2 3 4 5"|awk -v fff="$fff" -v dc="$dc" '{printf fff, dc}' ### NOT OK
awk: (FILENAME=- FNR=1) fatal: not enough arguments to satisfy format string
`%-3s %-3s
'
^ ran out for this one