Shell Script Trick No. 2
Reading files. Over the years I have used a couple of different methods for reading configuration files.
I present the two I have used the most with the second being my current favorite.
cat config | while read line
do
LINE=`echo $line | cut -d: -f2`
if [ "$LINE" = "#" ];then
echo
else
echo "$LINE:\c"
fi
done
#The read command eats leading spaces
exec < ${datafile}
while read line
do
# Don't process lines with comments just skip them.
if ( echo $line | grep "^#" > /dev/null 2>&1 );then
continue
fi
done
No comments:
Post a Comment