I've searched online about this problem and I've found two ways so far:
while read line; do
commands
done < "$filename"
and
for $line in $(cat $filename); do
commands
done
none of these work if the lines have a space though, for example if we have a line like that
textextext text
it won't print textextext text
but
textextext
text
it counts these things as a different line, how can I avoid this to happen?
Like this?
while IFS= read line ; do
something "$line"
done <"$file"
Here is a brief test:
while IFS= read line ; do echo "$line"; done <<<"$(echo -e "a b\nc d")"
a b
c d
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With