![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Read from text file misses first line | davewg | Shell Programming and Scripting | 2 | 03-12-2009 12:26 PM |
| A script that read specific fileds from the 7th line in a file | samura | Shell Programming and Scripting | 2 | 02-27-2009 06:26 AM |
| shell script to read data from text file and to load it into a table in TOAD | pallavishetty | Shell Programming and Scripting | 1 | 10-31-2008 04:15 AM |
| Script to add a single line to middle of text file. | progkcp | Shell Programming and Scripting | 2 | 05-12-2008 02:44 PM |
| read a file as input and pass each line to another script | sajjad02 | Shell Programming and Scripting | 0 | 09-24-2004 11:13 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|