I have the following array
components=('xx' 'xy' 'xz' 'yx''yy''yz''zx''zy''zz')
And I'm doing the following loop for all components
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
How come awk tells me I have a syntax error for
$2 == ${i: -1}
yy''yz''zx''zy''zz'.awkcommand withoutif-elif-elif-fi), but I don't see what you really want. I think$((100*$a))is not relevant for your question. You use$1 == "*", is this the first field of a line from your inputfile or do you call your loop with variabeles? It seems that you want this for componentxy: Look for the last line in thexy_inputfile that starts with* xy(*not a wildcard) and append the 4th field of that line to your output. Is this what you want?${i}.inand${i}.out.