I have a text file that contains several email messages in it. I'm trying to write a shell script that will read this file and parse each email out to a separate text file. The individual files are begun whenever I read a unique text line. Sample code is below. The problem is that the initial file contains leading spaces on some lines as well as blank lines. These must all be maintained in the individual output files. I thought that enclosing the output line $LINE in quotes would retain the leading spaces (it does from the command line), but it did not. This is running on Linux 6.1. Any suggestions would be most appreciated!
FILE=emails.txt
FILECNT=0
while read line
do
if [ `echo $line | grep "Unique data"` ]
then
FILECNT=` expr $FILECNT + 1`
OUTFILE=email$FILECNT.txt
fi
echo "$LINE" >> $OUTFILE
done < $FILE
Thanks,
Steve
FILE=emails.txt
FILECNT=0
while read line
do
if [ `echo $line | grep "Unique data"` ]
then
FILECNT=` expr $FILECNT + 1`
OUTFILE=email$FILECNT.txt
fi
echo "$LINE" >> $OUTFILE
done < $FILE
Thanks,
Steve