Except Script to read data from file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Except Script to read data from file
# 8  
Old 09-23-2015
Quote:
Originally Posted by Corona688
The loop probably doesn't do what you think it does anyway.

'for' does not loop on lines, it loops on words. If any of your lines have spaces in them, it will not be lines. To read lines:

Code:
while read line
do
        echo "line was $line"
done < inputfile

If you look closely at post #6, kidSandy did set IFS to a <newline> (instead of the default <space><tab><newline>), so the for loop in post #6 does process lines instead of words. But, it still silently skips empty lines in the input file (although it does correctly print non-empty blank lines).

But, I agree that 99 and 44/100% of the time:
Code:
while read -r line
do	printf 'input line: "%s"\n' "$line"
done < inputfile

is better than a for loop for two main reasons:
  1. The entire file does not have to be read into the address space of the shell before the loop starts.
  2. Empty lines are NOT silently discarded.
Note also that unless the contents of the file are known beforehand and the operating system and shell that will be used to run the script are known, using echo instead of printf can produce unexpected/undesired output if the input file contains any backslash (\) characters.

But, of course, until we hear more about what Geekris is really trying to do and what the input looks like; we can't be sure whether or not any of this makes any difference.
This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 09-25-2015
thanks for the replies ..Here is my script looking like & my requirement,
We have installer ,

Code:
#!/usr/bin/expect

spawn ./install.sh -i console

expect "*License agreement*"
send " <data from file >"
expect "*Path to install*"
send ""<Data from file>"

File.txt  <<< Inputs in Key=value pair
<
License agreement = yes
Path = /test/
.
.
.>

Is it possible in expect to send data from a file .. I am not getting how to send file contents,i dont want to hard code my values in script rather want to read from file & send it to installer script.

Looking forward for help.

Last edited by Don Cragun; 09-25-2015 at 01:23 AM.. Reason: Add CODE AND ICODE tags.
# 10  
Old 09-29-2015
Any suggestions

Last edited by Geekris; 09-29-2015 at 01:58 AM.. Reason: adding code tag
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

2. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

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

4. Shell Programming and Scripting

How to read file and load data into a script as variable

I need to read a text file that contain columns of data, i need to read 1st column as a function to call, and others are the data i need to get into a ksh script. I am quite new to ksh scripting, i am not very sure how to read each row line by line and the data in each columns of that line, set... (3 Replies)
Discussion started by: gavin_L
3 Replies

5. Shell Programming and Scripting

Script to read file and extract data by matching pattern

Hello, I have a file ( say file1) which has lines like below. xxxx:xxxx,yyyy,1234,efgh zzzz:zzzz,kkkk,pppp,1234,xxxx,uuuu,oooo dddd:dddd here the word before ":" ( ie: xxxx) is the file name and the string after : are also file names, but each file name separated by "," In case of... (20 Replies)
Discussion started by: pradeepmacha
20 Replies

6. Shell Programming and Scripting

Read data from .csv file through shell script & modify

I need to read data from a file called "test.csv" through shell script where the file contains values like name,price,descriptor etc. There are rows where descriptor (& in some rows name) are written as string & other characters like "car_+" OR "bike*" etc where it should contains strings like... (3 Replies)
Discussion started by: raj100
3 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

Help required with a Csh script to read data from a file

Dears, This is what i want.. I need to read a comma separated text file whose name is config.txt. whose content is like ; bscnara,btserrr bscsana,btssanacity ..... i need to read the first string and second string and use it to execute a another shell script. This is the logic. ... (1 Reply)
Discussion started by: fizzme
1 Replies
Login or Register to Ask a Question