I have a shell script that carries out an extraction process as follows:
For a given input file dummy which looks like the following:
a.txt
a 1
a 2
xnzbcnzbxcbzxncbmnzxbcmzx
546
456
45
5
6
56
a 3
b.txt
b1
b2
b3
the shell script returns two files called a.txt and b.txt followed by their corresponding content.
a.txt would contain the following content:
a 1
a 2
xnzbcnzbxcbzxncbmnzxbcmzx
546
456
45
5
6
56
and b.txt would contain the following content:
b1
b2
b3
the problem is when i run the script where the first line of dummy is not x.txt i get errors.
Example if dummy contained
asdasda
fg
grtjiogoirjtgdjkljdfslkjdf
a.txt
qwe
ert
tyu
then when i run the script i get the following ouput:
./extracter: line 8: $FILENAME: ambiguous redirect
./extracter: line 8: $FILENAME: ambiguous redirect
./extracter: line 8: $FILENAME: ambiguous redirect
but it still produces a.txt
Here is the script:
cat dummy |while read LINE
do
if [ "`echo ${LINE} |grep '.txt'$`" != "" ] ; then
FILENAME=${LINE}
continue
fi
echo $LINE >> $FILENAME
done
does anyone know how i can fix the problem.
thanks