The code is ;
cm=$1
nm=$2
case $cm in
"out")
declare -a en
declare -a inf
ec=$(grep -n "! " hw1_out_si_wire.txt)
IFS=$'\n' en=($ec)
lst=$((${#en[@]} -1))
IFS=' ' inf=($en[$lst])
echo " Energy: ${inf[4]} ${inf[5]}"
;;
"in") echo "It's not my problem";;
esac
And I'm trying to take 7th element of $en but the output is ;
[7]ergy: -1090.13343774 Ry
And the $en array is ;
! total energy = -1090.13343774 Ry
! total energy = -1090.20757070 Ry
! total energy = -1090.24296462 Ry
! total energy = -1090.25563488 Ry
! total energy = -1090.27085564 Ry
! total energy = -1090.27693129 Ry
! total energy = -1090.28213580 Ry
! total energy = -1090.29131927 Ry
So, what is the problem with this code ?Why is the output like this ?
Note:If the informations given is not enough , please inform me.
[7]tringwhen I'm expectingsomestring [7]I suspect Windows-style CR-LF line-endings are involveddos2unixit.awk -F'[\r ]+' '/^!/ {c++} ; c==7 { print " Energy:",$5,$6 }' hw1_out_si_wire.txt- this works whether it's a dos text file or unix format.