AtSim1 AtSim1 - 1 year ago 135
Bash Question

Printing line from file in bash script

I have a .txt file which contains text.

Line 1
Line 2
Line 3
End of file aka last line

How can I get print lines from the file and print them to the terminal using a bash script?

Is it possible to use a while loop to get line by line from the txt file and print them out ?

Answer Source

To read a file, line by line, you can use this:

while read line; do
    echo $line
done < file
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download