Shell script to send an email from the txt file

Hi Friends,

Could you guys help me out of this problem... I need to send an email to all the users and the email has to be picked from the text file.
text file contains the no. of records like:

giridhar
224285
847333
giridhar276@gmail.com
ramana
84849
33884
venkata.ramana@gmail.com
kishore
838393
484949
kishore.pulapa@gmail.com
venkat
434334
343433
venkateswararao@gmail.com

Every four lines make one record. For example consider the first record. I need to send a mail to giridhar276@gmail.com containing the his details "giridhar,224285,847333".
Now the details in the second record(next four lines) has to be sent to venkata.ramana@gmail.com

Like wise I need to send an email to other users alsooo......

Please help me.....

What have you tried so far, where are you stuck?

Thanks alot for replying me .....

My requirement is to send only his details to his user id.. But I was unable to do that.......

Here, I was reading each line and storing every 4th line and sending all other details as well(but it's not my requirement).
I has to send only his particular details as I mentioned....

cat myfile.txt | while read line
do
count=`expr $count + 1`
if [ `expr $count % 4` != 0 ]
then
  mail -s "Please check your details" $line < mytext.txt
fi
done

Please help me.....

cat myfile.txt | while read line
do
count=`expr $count + 1`
if [ $count -eq 1 ]
then
    detail_1=$line
elif [ $count -eq 2 ]
then
    detail_2=$line
elif [ $count -eq 3 ]
then
    detail_3=$line
elif [ $count -eq 4 ]
then
    count=0
    echo $detail_1" "$detail_2" "$detail_4|mail -s "Please check your details" $line
fi
done

This will do your work, tough not so optimized.

while read a
do
read b
read c
read email
echo $a $b $c |mail -s "your stuff" $email
done

Don't forget the input file. Note that this method is more efficient than cat'ing the file and piping it to the while loop (you might get a useless use of cat award reconstruction of the Award text. :slight_smile: One less process needed. There are some other good tips on that page too.

In a compact way...

cat <input_file> | paste -d, - - - - | sed 's,^,echo \",g;s,\,,\" | mail -s \"Record Details \" ,3' | sh