im trying to read from a file line by line using a 'for' loop is it possible in bash?
yes it is!
how do i do it?
can you help me
i have tried
for i in $(cat $file)
do
echo $i
done
its output is word by word by wanted to read the whole line
something like:
for i in `cat /path/to/file`
do
your code here
done
Try seeting IFS to some character which is not in the file you which to read i.e.
IFS=:
for i in $(cat $tmp)
do
echo $i
done
It is an IFS issue, which default can vary from shell to shell (sh, bash, ksh ...) if I remember correctly.
Actually, DukeNuke2's code is the same as the original one. Try this:
IFS=$'\n'
for i in $(cat $file)
do
echo "$i"
done
Why don't you use a while loop?
SPOT ON mate!! thanx it did work!
but he took the code from my post... look at the timestamp of the posts...
use a while loop like radoulov says. Its also meant for reading files in bash, without using cat
while IFS= read -r line
do
....
done < "file"
While Does the Trick