Script does not read the last line of text file

Hello,
I have got a script that reads a text file, and have got three problems that I an struggling with.

  1. The script does not read the last line in the text file

  2. within the second 'elif' within the script I included a 'break' - the script runs successfully (except for the first problem) , but if a situation occurs where the second 'elif' is executed the echo message is shown and all seems to work well, but if I try and run the script a second time with a condition that does not satisfy the second 'elif' the echo from the second 'elif' is still being shown' - this problem ony happens after the second 'elif' is executed at least once.

  3. Instead of breaking out of the code within the second 'elif' I wanted the user to be taken back to the first echo where they are asked to enter the 'Test Day'

I tried goto but after doing some research I realise that I am using Korn Shell and I cann use goto

CAN ANYONE HELP?

===sCRIPT ====

#!/bin/ksh

echo 'Please enter the Test Day or 0 for all days: '
read x
count=0
while read line
do
echo $line | read a b c d
if [ "$a" = "$x" ] ; then

      \( IFS=-
 printf ' 1\\n 1\\n 0\\n 0\\n 1\\n 1\\n 7\\n 0\\n'
 printf ' %s\\n' $c
 printf ' 1\\n 1\\n 0\\n 0\\n 0\\n N\\n 1\\n 100\\n' \) | 
 "$LOTO"/bin/loto_tsim > /dev/null 2>&1

let count=count+1
echo "Wager Number ${count} is:" $c

elif [ "$x" = "0" ] ; then

                   \( IFS=-
  printf ' 1\\n 1\\n 0\\n 0\\n 1\\n 1\\n 7\\n 0\\n'
  printf ' %s\\n' $c
  printf ' 1\\n 1\\n 0\\n 0\\n 0\\n N\\n 1\\n 100\\n' \) | 
  "$LOTO"/bin/loto_tsim > /dev/null 2>&1
              
let count=count\+1
echo 'Your wager is: ' $c 

   
 elif  [ "$a" != "$x" ]  || [ "$a" != "0"  ] ; then

                            echo 'Sorry The Test Day Entered Does Not Exist'
                            break

fi

done  < LottWagers2.txt 

=======text file data= ====

3 1 01-02-27-28-29-30 (99) Both 1
1 1 01-31-32-33-34-35 (99) Both 3
1 1 03-06-09-10-20-21 (99) Both 3
1 1 05-31-32-33-34-35 (99) Both 3
1 1 07-06-09-10-20-21 (99) Both 3
4 1 05-07-08-09-10-25 (99) Both 4
4 1 01-02-10-11-24-25 (99) Both 7
4 1 01-02-31-32-33-34 (99) Both 5
4 1 04-02-31-32-33-34 (99) Both 5

I'm just a starter in UNIX Scripting but think you could try the following:

  1. Reason why it doesn't read the last line might be due to missing newline. Open your text file again in VI editor and save and quit using ":wq". That will take care of the newline character issue.
  2. In the IF-ELSE block, instead of using "=" try using "==" or "-eq"
  3. Put the whole code in a while loop. Use some flag say gotoMenu = true and keep going back to MENU till the flag is set to FALSE.

Hope this helps.

regards,
Arun.

arunsoman80,

Thank you very much for your help, you suggestion for problem number 1 works fine. I will try suggestion 2 & 3 and tell you if it works.

Thanks again