Bash - How to make For read lines instead of words in a list ?
First of all, forgive me for i am noob :) , i searched the forum, but found no answers.
orders.txt contains the following Code:
one two three Code:
#!/bin/bash one two three this is a word I need it to print one two three this is a word I know i can achieve this by replacing spaces by _ or any other character, but is there other way to do it ? |
this does it for me:
Code:
for line in `cat ./orders.txt` hth |
The perl solution is trivial, if it this helps for anything.
while (<>) { chomp; print "line: $line\n"; } I have spend some time on your question and I can not figure out how to do that in pure bash. I would like to know a solution, if any exists. |
Code:
echo $ORDERS | while read line; do |
Thanks for the replies, i tested both ideas,
schneidz's solution gives the same result i got... one two three this is a word phil.d.g's gives as a result all the words from the text in the same line: one two three this is a word So far i have 3 solutions, but there must be an easier way to show each line separatedly. Use the tail , head trick Put a number for each line in the file and use grep Use lines without spaces. |
Oh, seems the line endings are lost when you do
Code:
ORDERS=`cat orders.txt` Code:
cat orders.txt | while read line; do |
Code:
while i=$(line) |
The idea behind all this is a script which reads instructions from a formated text file. Upon reading each line it will know if the task has been completed, or not and if i has to be executed now. It will then write the file if the task
was executed. This script will be checking the instructions file all the time, so the code should be as simple as posible. |
It works great now, thank you very much!
I think there is a way to tell "for" with a special parameter, to read lines intead of words, i was reading that in the bash manual, but i couldn't understand how. |
Quote:
Code:
IFS="$(echo)" |
Quote:
glad you got it regardless. |
All times are GMT -5. The time now is 09:49 PM. |