Iterate a Text File in Bash

Tagged with: , , ,

This is how you iterate thru a text file outputting a line at a time in Bash shell scripting.

IFS=$'\n'; for i in $(cat FILE.TXT); do echo "$i"; done

One Response to “Iterate a Text File in Bash

  • 1
    June 20th, 2012 20:31

    Actually, this is how not to do it — it starts a useless cat process and needs to store the whole file in memory. The right way to do it goes like this:

    while read line
    echo $line
    done < FILE.TXT

Leave a Reply