fabianmoronzirfas
1/26/2013 - 3:55 PM

shell loop a file line by line

shell loop a file line by line

#!/bin/sh
#this loops thru the lines of a file
#make shure you have unix lineendings
#@author: @fabiantheblind
#
if [ $# -ne 1 ]
then echo "Usage: THIS_FILE.sh filename";
exit 1;
fi

if [ ! -f $1 ]
then echo "File $1 doesn't exist";
exit 1;
fi

IFS_=${IFS}; IFS=$'\n'
for i in `cat $1`;do
    echo $i;
done
IFS=${IFS_}