I'm fairly new to bash scripting, and I wrote the following script to read a text file, run a while loop with if statements, and write the data I want into another text file.
#!/bin/bash
#
#
#
variable1=0
variable2=0
variable3=0
variable4=0
cat input.txt | while read Column1 Column2 Column3
do
if ["$Column1" = variable2]; then
if ["$Column2" > variable3 && "$Column2" < variable4]; then
if ["$Column3" > variable4]; then
variable4="$Column3"
continue
fi
else
echo variable1 variable2 variable3 variable4
variable1++
variable3="$Column2"
variable4="$Column3"
fi
else
echo variable1 variable2 variable3 variable4
variable1++
variable2="$Column1"
variable3="$Column2"
variable4="$Column3"
fi
done>output.txt
However when I run the script I get the following error message:
./code.sh: line 31: syntax error near unexpected token `done'
'/code.sh: line 31: `done>output.txt
I'd really appreciate if anyone could help me with this!
I don't know what you want to do but there are a lot of things one can fail in bash, i posted a tested version.
ps I was criticized that the code is a picture:)) here you have it for copy paste
#!/bin/bash
let variable1=0
let variable2=0
let variable3=0
let variable4=0
cat input.txt | while read Column1 Column2 Column3
do
if [ "x$Column1" == "x$variable2" ]; then
if [ "x$Column2" -gt "x$variable3" ] && [ "x$Column2" -lt "x$variable4" ]; then
if [ "x$Column3" -gt "x$variable4" ]; then
let variable4=$Column3
continue
fi
else
echo $variable1 $variable2 $variable3 $variable4
let "variable1 += 1"
let variable3=$Column2
let variable4=$Column3
fi
else
echo $variable1 $variable2 $variable3 $variable4
let "variable1 += 1"
let variable2=$Column1
let variable3=$Column2
let variable4=$Column3
fi
done > output.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.