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:
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:
is better than a for loop for two main reasons:
The entire file does not have to be read into the address space of the shell before the loop starts.
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:
thanks for the replies ..Here is my script looking like & my requirement,
We have installer ,
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.
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)
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)
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)
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)
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)
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)
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)
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)
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)