我使用 awk 编写了这个脚本,但它无法正常工作。即使我只期望只显示特定列,它也会向我显示全部信息列。
n=0
echo "Enter which column you want: "
read n
awk '{print $($n)}' out.txt
我只想为 n
的值指定特定列。
谢谢
最佳答案
单引号内没有参数替换。使用
awk '{print $'$n'}' out.txt
或者使用 awk 变量,如
awk -v n="$n" '{print $n}' out.txt
关于shell - awk 脚本未列出特定列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12320951/