title: Embedding awk in a shell script
body: <p>I've been using a bash script (script.sh) which uses various awk scripts (script1.awk,script2.awk) which are tailored at "runtime", by replacing values for instance.
  I've been looking for ways to embed them completely within the first bash script.
  Ideally, I would like to have a file looking like this : </p>
  
  <pre><code>################################
  # AWK scripts                  #
  ################################
  read -d '' scriptVariable &lt;&lt;'EOF'
  '
  {my block commands;}
  '
  EOF
  ################################
  # End of AWK Scripts           #
  ################################
  awk $scriptVariable ${inputfile} # This line obviously doesn't work
  </code></pre>
  
  <p>instead of the traditional : </p>
  
  <pre><code>awk '{
  my script commands
  ' ${intputfile}
  </code></pre>
  
  <p>Of course, I could write them to a file but the whole point is not to. Any suggestions ?</p>
  
  <p>EDIT : Although dogbane answers works fine, the next problem is that with the &lt;&lt;'HERE' tags, newline characters are not read.I can't unquote it since, otherwise, he's trying to interpret the awk script then encountering a $ sign within (and there are). And with no newlines, I can't comment anything within the awk script (without commenting half the script when the newlines characters are being removed ...). Anyone ?</p>
  
  <pre><code>&lt;&lt; 'EOF'
  BEGIN{#Hello
  print $1
  }
  EOF # Is read as BEGIN{#Hello print $1} by awk; ie BEGIN{
  
  &lt;&lt; EOF
  BEGIN{#Hello
  print $1
  }
  EOF #Is read correctly by awk but Bash tried to express $1 and fails
  </code></pre>