Using Shell Script to get data from text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using Shell Script to get data from text file
# 1  
Old 03-13-2009
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, and depending on the Test Day entered (in this case 1, 2 or 4) the script will extract first instance of the required data from the related line, send the fist set of data to the tsim scrpt and then move on to the next.....CAN ANYONE HELP PLEASE

-----Current Script--------------------
#!/bin/sh
Please enter the Test Day - Enter 0 for all : "
read x
( read a b c d < LottWagers2.txt
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

--------------------------------------------------


-----------text file content-----------------------

1 1 01-02-25-26-27-28 (99) Both 1
1 1 26-27-28-29-30-31 (31) Both 1
1 1 01-02-27-28-29-30 (99) Both 1
2 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-13-2009
Quote:
Originally Posted by jermaine4ever
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, and depending on the Test Day entered (in this case 1, 2 or 4) the script will extract first instance of the required data from the related line, send the fist set of data to the tsim scrpt and then move on to the next.....CAN ANYONE HELP PLEASE

Please put code inside [code] tags.
Quote:
-----Current Script--------------------
Code:
#!/bin/sh
Please enter the Test Day - Enter 0 for all : "
read x
 ( read a b c d < LottWagers2.txt
   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


Code:
grep "^$x" LottWagers2.txt | {
 read a b c d
 ....
} | ....

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Inserting shell script input data automatically from a text file

Dear experts, I am new to linux programming. I have a shell script which i should run it on all my samples. I only define input and out put for this script. The inputs are 3 numbers(coordination numbers) which are available in a series of text file. Since i have a lots of samples, it takes a... (5 Replies)
Discussion started by: mohamadreza
5 Replies

2. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

3. Shell Programming and Scripting

How to write text file data to excel using UNIX shell script?

Hi All, I have the requirement in unix shell script. I want to write the "ls -ltr" command out put to excel file as below. Input :text file data : drwxr-xr-x 5 root root 4096 Oct 2 12:26 drwxr-xr-x 2 apx aim 4096 Nov 29 18:40 drwxr-xr-x 5 root root 4096 Oct 2 12:26 drwxr-xr-x... (10 Replies)
Discussion started by: Balasankar
10 Replies

4. 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

5. Shell Programming and Scripting

regular expression with shell script to extract data out of a text file

hi i am trying to extract some specific data out of a text file using regular expressions with shell script that is using a multiline grep .. and the tool i am using is pcregrep so that i can get compatibility with perl's regular expressions for a sample data like this, i am trying to grab... (6 Replies)
Discussion started by: vemkiran
6 Replies

6. Shell Programming and Scripting

Bash shell script that inserts a text data file into an HTML table

hi , i need to create a bash shell script that insert a text data file into an html made table, this table output has to mailed.I am new to shell scripting and have a very minimum idea of shell scripting. please help. (9 Replies)
Discussion started by: intern123
9 Replies

7. 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

8. Shell Programming and Scripting

Shell script to read lines in a text file and filter user data

hi all, I have this file with some user data. example: $cat myfile.txt FName|LName|Gender|Company|Branch|Bday|Salary|Age aaaa|bbbb|male|cccc|dddd|19900814|15000|20| eeee|asdg|male|gggg|ksgu|19911216||| aara|bdbm|male|kkkk|acke|19931018||23| asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
Discussion started by: srimal
4 Replies

9. Shell Programming and Scripting

shell script to read data from text file and to load it into a table in TOAD

Hi....can you guys help me out in this script?? Below is a portion text file and it contains these: GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL005675 000001... (1 Reply)
Discussion started by: pallavishetty
1 Replies

10. Shell Programming and Scripting

Need Shell Script to upload data from Text file to Oracle database

Hi Does any one have any idea on uploading the data using Unix Shell script from text file to Oracle database. Requirement:- 1. Need to connect to Oracle database from Unix Shell script. 2. Need to pick Text file from some location on Unix Box. 3. Need to upload the data from text file to... (6 Replies)
Discussion started by: chandrashekharj
6 Replies
Login or Register to Ask a Question