Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 489
webminal.org Avatar asked Jan 27 '11 05:01

webminal.org


People also ask

What does read line do in bash?

We can use the read command to read the contents of a file line by line. We use the -r argument to the read command to avoid any backslash-escaped characters. In the following example, we can see that we have an iteration over a file line by line and we store the contents of a single line in the variable “line“.


1 Answers

while read -r line; do echo "$line"; done < file.txt
like image 84
SiegeX Avatar answered Sep 17 '22 16:09

SiegeX