The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2009
jermaine4ever jermaine4ever is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 21
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
  #2 (permalink)  
Old 03-18-2009
arunsoman80 arunsoman80 is offline
Registered User
  
 

Join Date: Jul 2008
Location: New York
Posts: 45
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.
  #3 (permalink)  
Old 03-18-2009
jermaine4ever jermaine4ever is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 21
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0