Process each line of a file in bash

Solution 1:

You don't need to use cat:

while read line; do
    echo "$line"
done < my_file

I don't think there's a simpler way though.

Solution 2:

The simplest, I think, would be to use xargs, e.g.,

xargs -L1 gzip < my_file

The -L1 option tells xargs to process one input line at a time. You might take a look at GNU parallel, too, which is very similar to xargs but more powerful in some situations.

Solution 3:

IFS="\n\b"; for i in $MYROWOFCONTENT; do echo $i; done;