Script extracting the incorrect data from text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script extracting the incorrect data from text file
# 1  
Old 03-16-2009
Script extracting the incorrect data from text file

Hello,
A script has been written to extract a specific column data from a text file ONLY if the user's initial input matches the the data of the first column in the text, then only the data from that row will be prinited.

The problem I am having is that the code is only reading the records highlighted in red from the text file. It should only read the lines where the first column matches the user's input.

CAN ANYONE HELP?


===================Shell Script=======================

#!/bin/sh

print 'Please enter the Test Day or 0 for all days: '

read x

while read line
do
read a b c d

if a==x
then
( IFS=-
printf ' 1\n 20\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

print 'X is now equals to : ' $x
print 'First Col equals to : ' $a
print 'Your wager is: ' $c
fi

done < LottWagers2.txt



============= LottWagers2.txt =============

1 1 01-02-27-28-29-30 (99) Both 1
1 1 01-31-32-33-34-35 (99) Both 3
2 1 01-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
# 2  
Old 03-16-2009
Try this:
Code:
while read line
do 
echo $line | read a b c d

# 3  
Old 03-16-2009
Thank you Goldorakk, I will try it now and see if that works
# 4  
Old 03-16-2009
Quote:
Originally Posted by Goldorakk
Try this:
Code:
while read line
do 
echo $line | read a b c d

Hello GOLDARAK,

I tried the code you supplied, but am getting the error below. It is still picking up data where the first column is NOT 1 and it does like the way I am comparing (IF a==x )

Please enter the Test Day or 0 for all days:
1
X is now equals to : 1
First Col equals to : =x
Your wager is: 01-02-27-28-29-30
X is now equals to : 1
First Col equals to : =x
Your wager is: 01-31-32-33-34-35
X is now equals to : 1
First Col equals to : =x
Your wager is: 01-06-09-10-20-21
X is now equals to : 1
First Col equals to : =x
Your wager is: 05-07-08-09-10-25
X is now equals to : 1
First Col equals to : =x
Your wager is: 01-02-10-11-24-25
# 5  
Old 03-16-2009
Sorry, I didn't see this -second- bug ... Smilie
Code:
while read line
do
 echo $line | read a b c d

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

Result:
Code:
Please enter the Test Day or 0 for all days: 
1
X is now equals to :  1
First Col equals to :  1
Your wager is:  01-02-27-28-29-30
X is now equals to :  1
First Col equals to :  1
Your wager is:  01-31-32-33-34-35

# 6  
Old 03-16-2009
Well, before you ask for the "0" case ... Smilie :
Code:
read x

while read line
do
 echo $line | read a b c d

if [ "$a" = "$x" ] || [ "$x" = "0" ]
then
( IFS=-
printf ' 1\n 20\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

print 'X is now equals to : ' $x
print 'First Col equals to : ' $a
print 'Your wager is: ' $c
fi

# 7  
Old 03-16-2009
Goldarakk,
YOU ARE A STAR, IT WORKS LIKE A CHARM.

tHANK YOU VERY MUCH I REALLY APPRECIATE THIS
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script for extracting data from csv file based on column values.

Hi all, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 5 columns having values say column 1,column 2.....column 5 as below along with their valuesm.... (3 Replies)
Discussion started by: Vivekit82
3 Replies

2. Shell Programming and Scripting

Need help on inserting data from text file to excel using shell script

Hi, Please help me on this. I want to insert data from text file to excel using shell script nawk -v r=4 -v c=4 -v val=$a -F, 'BEGIN{OFS=","}; NR != r; NR == r {$c = val; print}' "file.csv" I used above one to insert $a value in 4th row, 4th column in an excel file.csv and it... (3 Replies)
Discussion started by: suman.frnz
3 Replies

3. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

4. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

5. Shell Programming and Scripting

How to read the data from the text file in shell script?

I am having one text file and i need to read that data from my shell script. I will expain you the scenario: Script look like: For name type 1: For age type 2: For Salary type3: echo "Enter the input:" read the data if input is 1 then go to the Text file and print the... (2 Replies)
Discussion started by: dineshmurs
2 Replies

6. Shell Programming and Scripting

Extracting a portion of data from a very large tab delimited text file

Hi All I wanted to know how to effectively delete some columns in a large tab delimited file. I have a file that contains 5 columns and almost 100,000 rows 3456 f g t t 3456 g h 456 f h 4567 f g h z 345 f g 567 h j k lThis is a very large data file and tab delimited. I need... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

7. Shell Programming and Scripting

Using Shell Script to get data from text file

Hello, I have got the script below that reads a text file and then extract data from the third column and then send the result to another shell scrpt call tsim - the script works fine. The problem I am having is that I want the user to enter the 'Test Day' which the first column in the text file,... (1 Reply)
Discussion started by: jermaine4ever
1 Replies

8. UNIX for Dummies Questions & Answers

extracting text and reusing the text to rename file

Hi, I have some ps files where I want to ectract/copy a certain number from and use that number to rename the ps file. eg: 'file.ps' contains following text: 14 (09 01 932688 0)t the text can be variable, the only fixed element is the '14 ('. The problem is that the fixed element can appear... (7 Replies)
Discussion started by: JohnDS
7 Replies

9. Shell Programming and Scripting

urgent-extracting block data from flat file using shell script

Hi, I want to extract block of data from flat file. the data will be like this start of log One two three end of log i want all data between start of log to end of log i.e One two three to be copied to another file. This particular block may appear multiple times in same file. I... (4 Replies)
Discussion started by: shirish_cd
4 Replies

10. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies
Login or Register to Ask a Question