我有以下数组
components=('xx' 'xy' 'xz' 'yx''yy''yz''zx''zy''zz')
我正在对所有组件执行以下循环
for i in "${components[@]}"
do
if [ ${i: -1} == "x" ]; then
awk '$1 == "*" && $2 == ${i: -1} {v=$3} END {print v}' ${i}_E_cutoff_$((100*$a))_eV/$systemID.castep >> Stress_${i}_vs_Ecutoff_convergence.txt
elif [ ${i: -1} == "y" ]; then
awk '$1 == "*" && $2 == ${i: -1} {v=$4} END {print v}' ${i}_E_cutoff_$((100*$a))_eV/$systemID.castep >> Stress_${i}_vs_Ecutoff_convergence.txt
elif [ ${i: -1} == "z" ]; then
awk '$1 == "*" && $2 == ${i: -1} {v=$5} END {print v}' ${i}_E_cutoff_$((100*$a))_eV/$systemID.castep >> Stress_${i}_vs_Ecutoff_convergence.txt
fi
done
awk怎么告诉我我的语法错误
$2 == ${i: -1}
答案 0 :(得分:1)
之所以会出现语法错误,是因为您无法单独使用awk命令内部的外部变量。您首先需要将它们告诉awk。
关于此操作的非常好的帖子:How do I use shell variables in an awk script?
使用以上答案,您可以执行以下操作:
a$company<-as.factor(a$company)
ggplot(a, aes(x=company, y=value, fill=time)) + geom_col(position="dodge")
其中awk -v var=${i: -1} '$1 == "*" && $2 == var {v=$3} {print v}' ${i}_E_cutoff_$((100*$a)) _eV/$systemID.castep >> Stress_${i}_vs_Ecutoff_convergence.txt
是要注册供awk使用的变量。
希望这会有所帮助!