Search code examples
shellfileunixcsh

How to get email from each line and send that line as email to same address, in csh


I have a text file. I need to select the address mail from each line and send each line to the correspond address.

I try to use foreach and awk to select the address

set valuea = `awk '{print $3}' FichierNote`

Could you please give me a way how can i do this? This is the data in the file.

    8 mariamms maria@gmail.com (cto;MDG_MMS) 
    7 lj16 jean-christophe@gmail.com (gnb;DIG_FMTRD) 
    7 imbse emma.imbspi@gmail.com (gnb;MDG_MMS) 
    6 viviens stephano.vien@gmail.com (gnb;IMD) 
    5 alberghv vinco.alrghina@gmail.com (cto;ADG) 

Solution

  • You need to create a script like below:-

        #!/usr/bin/csh
    
    while read -r line
    do
      mailId=$(echo "$line" | awk '{print $3}')
      #echo $mailId
      #here you have to put your mail command
      #example 'sendmail -f source_mail_id.com $mailId < mailContentFile.txt'
    done < FichierNote
    

    How will the above script work? In while loop it will read each line and awk command will cut the mail id each time and will store in mailId variable. Now you need to put your mail command and put $mailId variable as email address.