Saturday, February 22, 2014

Bash: How to read file line by line

IFS=$'\n'

for line in $(cat file.txt)
do
       echo $line
done


OR

while read line
do
        echo $line
done < file

[While loop is the easiest method but it obliterates the formatting of lines including spaces and tabs.]


No comments: