title: How to send an E-mail with AWK using the SYSTEM command
body: <p>So I have this uni homework where I need to send an E-mail to all the people from a certain group of students (which are listed in the diak.lst file) and to attach the text from a file to the mail as well. The address of the students is in a similar form: xy9999, 2 characters and 4 numbers.
  The problem seems to be at the SYSTEM part, it says that there is no such thing as "attachedfile".</p>
  
  <p>The diak.lst is in the following format:</p>
  
  <blockquote>
    <p><em>F-Name,Name,Address,Group</em><br>
    George Peter gp9999 511  </p>
  </blockquote>
  
  <p>This is the script</p>
  
  <pre><code>#!/bin/bash
  if [ ! -f $2 ] 
      then echo $2 Not a file!!
      exit 1
  fi
  awk -v group=$1 -v attachedfile=$2 'BEGIN {fs=" ";nr_sent_to=0;}
  {
          if ($4==group){
  
      system("mail -s \"Attention!\"" $3 " &lt; " attachedfile);
      nr_sent_to++;
      } 
  }
  END {
  print nr_sent_to,"-have received the mail";
  }
  ' diak.lst
  </code></pre>