Reputation: 422
I have the following code:
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
set -u
se () { sed -n 's/\s*r('"$1"').*|r| =\s\+//p'}
### gets the number of cell opt steps
exec 0<"DEMLIR.out"
while read -r line
do
gawk 'BEGIN{FS="OPTIMIZATION STEP:"} {print $2}' | tr -s " "
done>results
sed -i '/^$/d' results
#sed -e 's/^[ \t]*//' results
step=$(tail -n 1 results)
echo "${step}"
### gets the number of steps in each geo_opt output
for i in $(seq 1 $step)
do
exec 0<"DEMLIR-GEO_OPT-$i.out"
while read -r line
do
gawk 'BEGIN{FS="OPTIMIZATION STEP:"} {print $2}' | tr -s " "
done>results_geo_$i
sed -i '/^$/d' results_geo_$i
step_geo=$(tail -n 1 results_geo_$i)
echo "${step_geo}"
### goes through each line in distance.out and prints distances to array
exec 0<"DEMLIR-GEO_OPT-$i-distance-1.coordLog"
while read -r line
do
for j in $(seq 0 $step_geo)
do
"$line" | se
paste -d' ' <(printf '%s\n' $j) <(se 1,5) <(se 2,5) <(se 2,8)
done
done
done>DEMLIR_task.txt
I try to run this program but I keep getting the unexpected end of line error
on line 53. I saw that there are already answers for this problem but when I try dos2unix
it says
dos2unix: converting file script_step.sh to Unix format...
but that's it. And when I run the code again it won't work.
I am expecting some errors at the last for loop, so if you see some you can also point them out. But if they are not related to the original problem then you can just ignore them.
Upvotes: 0
Views: 213
Reputation: 781878
The problem is here:
se () { sed -n 's/\s*r('"$1"').*|r| =\s\+//p'}
You need a semicolon or newline before the }
. Otherwise, it's treated as part of the sed
argument.
Upvotes: 1