为什么不能将 bash 中的命令移植到 awk 中?

Why can't transplant the command from bash into awk?

x="qwerty"
x=$(echo $x | tr [a-z] [A-Z]);
echo $x
QWERTY

想移植到awk中
1 另存为 format.awk

#! /usr/bin/awk
{
x=$(echo -n [=12=] | tr [a-z] [A-Z])
print $x 
}

2 awk -f format.awk 文件

awk: format.awk: line 3: syntax error at or near tr

为什么以及如何解决?

cat file |tr [a-z] [A-Z]翻译整个文件很容易,awk还有很多其他工作要做,所以有必要翻译awk 一行一行,其他任务省略。

你不能这样调用 tr:

你可以这样做:

awk '{print | "tr \"[a-z]\" \"[A-Z]\""}' file

或者最好完全在 awk 中完成,如:

awk '{line = toupper([=11=]); print line}' file