title: How does awk distinguish between arguments and input file?
body: <p>This is my shell script that receives a string as an input from the user from the stdin.</p>
  
  <pre><code>#!bin/sh
  printf "Enter your query\n"
  
  read query
  cmd=`echo $query | cut -f 1 -d " "`
  input_file=`echo $query | cut -f 2 -d " "`
  printf $input_file
  
  if [ $input_file = "" ]
  then
      printf "No input file specified\n"
      exit
  fi
  if [ $cmd = "summary" ]
  then
      awk -f summary.awk $input_file $query
  fi
  </code></pre>
  
  <p>Lets say he enters </p>
  
  <pre><code>summary a.txt /o foo.txt
  </code></pre>
  
  <p>Now <code>cmd</code> variable will take the value <code>summary</code> and <code>input_file</code> will take <code>a.txt</code>.
  Isn't that right?</p>
  
  <p>I want summary.awk to work on <code>$input_file</code>, based on what is present in <code>$query</code>.</p>
  
  <p>My understanding is as follows :</p>
  
  <ol>
  <li><p>The 1st command line argument passed is treated as input file.
  e.g. : <code>awk 'code' file arg1 arg2 arg3</code>
  only <code>file</code> is treated as input file</p></li>
  <li><p>If the input file is piped, it doesn't see any of the arguments as input files.
  e.g. : <code>cat file | awk 'code' arg1 arg2 arg3</code>
  <code>arg1</code> is NOT treated as input file.</p></li>
  </ol>
  
  <p>Am I right?</p>
  
  <p><strong>The problem is</strong>
  I get <code>awk: cannot open summary (No such file or directory)</code>
  Why is it trying to open <code>summary</code>? 
  It is the next word after <code>$input_file</code>.</p>
  
  <p>How do I fix this issue?</p>