I'm trying to create a script that will remove certain parts of a txt file full of status info and other various text. I can't end the main if statement. Also I'm trying to get it to delete the oldest status info by putting the date command into the script that generates the output.txt. Is there a way to make it delete the oldest info. I'm mainly trying to get the if statement to end. Thanks. (Also, I originally had the else if as elif's, but I got the same results.)
./count.sh: line 30: syntax error near unexpected token else'
./count.sh: line 30:
else'
WCOUNT=$(wc -l output.txt $1 | awk '{print $1}')
if [[ $WCOUNT -gt 50 ]]; then
if [[ "grep CLIENTSTART output.txt" != null ]]; then
echo $WCOUNT
sed -i '/\*\*\*CLIENTSTART/,/CLIENTEND\*\*\*/ d' output.txt
echo $WCOUNT
else if [[ -n "grep DHCPSTART output.txt" ]]; then
echo $WCOUNT
sed -i '/\*\*\*DHCPSTART/,/DHCPEND\*\*\*/ d' output.txt
echo $WCOUNT
else if [[ -n "grep DNSSTART output.txt" ]]; then
echo $WCOUNT
sed -i '/\*\*\*DNSSTART/,/DNSEND\*\*\*/ d' output.txt
echo $WCOUNT
else if [[ -n "grep WEBSTART output.txt" ]]; then
echo $WCOUNT
sed -i '/\*\*\*WEBSTART/,/WEBEND\*\*\*/ d' output.txt
echo $WCOUNT
else
echo "Cannot help you"
fi
else
echo "You're good, homie. It's under 500"
fi
wc|awk
pipeline actually outputs three numbers which are used as the value of WCOUNT; is that really what you want? If you only want the count of lines in a single file, you don't need awk, just redirection:WCOUNT=$(wc -l <output.txt)
. Also yourif [[ "grep something output.txt" ]]
tests don't actually look at the contents of the file output.txt; after fixing the nesting as answered, all of the tests will/would always succeed regardless of the contents of the file.elif
, as in Matt's answer should prevent theunexpected token else
error. If you're still seeing that message, can you show us theelif
version of your script that produces it?