Wednesday, July 06, 2005

File processing using shell scripts

cat myfile |
( while read LINE ; do
PART1=$( echo $LINE | cut -d ":" -f 1 )
PART2=$( echo $LINE | cut -d ":" -f 2 )
# let the shell assist your aim here
echo P1:$PART1
echo P2:$PART2
# ..
done )

executes the while loop in a subshell in all Bournish shells whereas

while IFS=: read PART1 PART2
do
...
done < myfile

#################################################################

while read line
do
set -- $line
done

No comments: