Search code examples
bashshellparsinglines

How to read entire line from bash


I have a file file.txt with contents like

i love this world

I hate stupid managers
I love linux

I have MS

When I do the following:

for line in `cat file.txt`; do
echo $line
done

It gives output like

I
love
this
world
I
..
..

But I need the output as entire lines like below — any thoughts ?

i love this world

I hate stupid managers
I love linux

I have MS

Solution

  • while read -r line; do echo "$line"; done < file.txt