The UNIX and Linux Forums  

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
Reading data from a specific line in a text file jermaine4ever Shell Programming and Scripting 4 04-02-2009 05:21 AM
how to insert data into database by reading it from a text file?? pallavishetty Shell Programming and Scripting 4 10-30-2008 08:02 AM
Adding specific text and spaces to each line in a text file hertingm Shell Programming and Scripting 4 08-25-2008 03:34 PM
reading text file line by line MizzGail Shell Programming and Scripting 6 04-14-2008 07:58 AM
reading specific line from file cool_boss2121 Shell Programming and Scripting 10 04-26-2005 10:05 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 04-01-2009
jermaine4ever jermaine4ever is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 21
Reading data from a specific line in a text file

hello,
I have got the following problem that I am hoping someone can help with please.

1. I have got the following text file (below) , the columns data are
'Test Day', 'Board', 'Betting Number'.



TEXT FILE
============================================

1 3 02-01-27-28-29-30
0 1 01-31-32-33-34-35
0 1 03-06-09-10-20-21
2 1 05-31-32-33-34-35
2 1 06-07-09-10-20-21
4 1 05-07-08-09-10-25
4 1 01-02-10-11-24-25
4 1 01-02-31-32-33-34
4 1 02-04-31-32-33-34
4 1 06-02-09-10-20-21

2. Consider a ticket system, that can have more that one boards (i.e
betting more than one numbers. So take for example the first line, the
board is 3, which means that one ticket will bet with Lin1, Line2 and
Line 3 Betting Numbers.
The problem I am having is that I cannot get the code to read Line2
and then Line 3 Betting Number because the board in Line 1 is greater
than 1.
The code works fine as it is, it reads each line in the text file and
send the data to another shell script ("$LOTO"/bin/loto_tsim
> /dev/null 2>&1 ) see code below

CODE ===========



#!/bin/ksh
#set -x

# This program extract data from a text file which holds wagering information for games and use these data as parameters
# for the TSIM (Transaction Simulator), which then generates various combinations of wagers (from the text file) using
# a vitual terminal (terminal 100)


main()
{
echo "\nPlease enter the Test Day or 0 for all days: "
read x

count=0
xcount=1
proveen=0

checker="false"

while read line ;

do


echo $line | read a b c d

if [ "$x" = "$a" ] ; then

( IFS=-
printf ' 1\n 1\n 0\n 0\n'
printf ' %s\n' $b
printf ' 1\n 7\n 0\n'
printf ' %s\n' $c

# HERE IS WHERE THE PROBLEM EXIST, IF I WANT TO EXTRACT $C FROM
# LINE 2 & 3 BECAUSE THE BOARD IN THE FIRST LINE IS 3
# THE CODE SHOULD EXTRACT THIS DATA BEFORE CONTINUING.
# IF THE BOARD IN THE FIRST LINE WAS 1, THEN THE CODE WOULD #EXECUTE AS NORMAL


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
checker="true"
echo "Wager Number ${count} is:" $c
echo 'the value of board is :' $b
echo 'the line number is :' $line


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
let lncounter=lncounter+1
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
checker="true"
echo "Wager Number ${count} is:" $c
else
let proveen=proveen+1



fi

done < LottWagers2.txt # Text file data is sent to the while loop
if [ "$checker" = "true" ] ; then
anotherchance
else
backup
fi
}

backup() {

echo "\nTest day not found, would you like to try again? [Y/N] : "

typeset -u pp
read ans
pp=$ans


if [ "$pp" = "Y" ] ; then

main
elif [ "$pp" = "N" ] ; then
echo "\n ******** GOODBYE ************ \n"
else
echo "\nUnrecognised entry \n"
fi
}

anotherchance()
{
echo "\nWould you like to wager again? [Y/N] : "

typeset -u pp
read wa
pp=$wa

if [ "$pp" = "Y" ] ; then
main
elif [ "$pp" = "N" ] ; then
echo "\n ******** GOODBYE ************ \n"
else
echo "\nUNRECOGNISED ENTRY"
anotherchance


fi

}

main
  #2 (permalink)  
Old 04-01-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,346
No duplicate or cross-posting, please read the rules.

Continue here:

Reading data from a specific line in a text file

Thread closed.
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 09:57 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