Thursday, 25 April 2013

Unix Shell Script - Reading a file using For loop

If you want to read whole/full line in for loop , you need to set IFS(Internal Field Separator) to new line which is by default space as  follows:

#!/bin/bash
OIFS=$IFS #Original Internal field separator
# Setting Internal Field Separator to new line
IFS="
"
for line in `cat filename`
do
echo $line
done

No comments:

Post a Comment