Skip to main content
edited tags
Link
muru
  • 78.4k
  • 16
  • 214
  • 321

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

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 

else echo "You're good, homie. It's under 500"

fi

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

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 
Source Link
Desert
  • 21
  • 1
  • 2

Syntax error near unexpected token 'else'

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