i need to split the file based on line and put that files in a array and need to access that files through loop finally i should send the files through mail..
how can we achieve this ..I am new to shell script please guide me..
split -l 2 line_test.txt line_test.txt
set -A TEST_ARRAY line_test.txta*
a=0
for i in ${TEST_ARRAY[@]}
do
echo " TEST_ARRAY[$a] : $i"
mv $i ./line_test_$a.txt
(( a = a + 1 ))
done
it is working ...I have searched and tried this...
But I dont know that the above is correct. Is there some nice way to do the same ?
If the text file is more than 10 rows ,i need to divide this file and send the divided files through mail...
what i have done is the below
LINE_COUNT=`wc -l $APPLTMP/${TXT_FILE_NAME} | cut -d " " -f8`
echo "LINE_COUNT :$LINE_COUNT"
if [ LINE_COUNT -gt 10 ]
then
split -l 10 $APPLTMP/$TXT_FILE_NAME $APPLTMP/$TXT_FILE_NAME
cd $APPLTMP
set -A FILE_ARRAY ${TXT_FILE_NAME}a*
a=0
for i in ${FILE_ARRAY[@]}
do
echo " FILE_ARRAY[$a] : $i"
#cp $i ./$APPLTMP/${TXT_FILE_NAME}_$a
(( a = a + 1 ))
done
set -A FILE_ARRAY ${TXT_FILE_NAME}a*
else
cd $APPLTMP
set -A FILE_ARRAY ${TXT_FILE_NAME}
fi
#
for i in ${FILE_ARRAY[@]}
do
#echo "inside for loop"
#
echo " $i"
if [ -f $APPLTMP/$i ]
then
(echo "Please find attached your requested report"
uuencode ${i} ${i}) | mailx -s "${i}" ${P_EMAIL}
fi
done