AtSim1 AtSim1 - 2 months ago 6
Bash Question

Printing line from file in bash script

I have a .txt file which contains text.

Eks:
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

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

while read line; do
    echo $line
done < file
Comments