Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Reading line by line



meino.cramer@xxxxxx wrote:
> Hi,
> 
>  how can I read line by line from a file of text?
> 
>  I tried
> 
>  while theline in `cat results.txt`
>  do
>      echo ${theline}
>      echo "----------------"
>  done
> 
>  and got a new echo on every _blank_ seperated word and 
>  not a every new line seperated by a newline.
> 
>  Thank you very much for any help in advance!
>  Keep zshing!

I'm assuming you meant "for" not "while"?

The `cat results.txt` will expand into the contents of results.txt,
which will then typically be split apart on wordspace, just as tokens
are normally split in a shell.

You probably want something more like:

while read theline
do
    echo ${theline}
    echo "---------------"
done < results.txt

HTH,

-- 
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/



Messages sorted by: Reverse Date, Date, Thread, Author