title: awk searching for multiple fields
body: <p>I encountered a difficulty during my assignment and would like some clarification.</p>
  <p>I have the following code to find book by author and title (or part of title e.g find Lego War VI and return 2 result /  find Scissorhands and find 3 results).
  However, if author is RETURN, find only by title. And if title is RETURN, find only by author.</p>
  <ul>
  <li><p>The problem comes when I have to use awk to find both author and title.</p>
  </li>
  <li><p>Can anyone guide me on the search_both function? the problem is that I am unable to search both fields and print out result.</p>
  </li>
  </ul>
  <p>For example. If I were to type in author = Lego and title = Lego Wars VI there should be only 1 field found,  which will print out.</p>
  <p>Lego Wars VI – Lego Legacy, Lego Company, $15.98, 20, 15</p>
  <pre><code>#!/bin/bash
  
  function search_title
  {
      awk -F':' -v search=&quot;$Title&quot; '$1 ~ search { i++; printf &quot;%s, %s,$%s,%s,%s\n&quot;, $1, $2, $3, $4, $5 } END { printf &quot;%d records found\n&quot;, i }' books.txt
  }
  
  function search_author
  {
      awk -F':' -v search=&quot;$Author&quot; '$2 ~ search { i++; printf &quot;%s, %s,$%s,%s,%s\n&quot;, $1, $2, $3, $4, $5 } END { printf &quot;%d records found\n&quot;, i }' books.txt
  }
  
  function search_both
  {
      awk -F':' -v search=&quot;$Title&quot; search1=&quot;$Author&quot; '$1 ~ search &amp;&amp; $2 ~ search1 { i++; printf &quot;%s, %s,$%s,%s,%s\n&quot;, $1, $2, $3, $4, $5 } END { printf &quot;%d records found\n&quot;, i }' books.txt
  }
  
  read -p $'Title: ' Title
  read -p $'Author: ' Author
  
  if [ &quot;$Title&quot; == &quot;&quot; ];
  then
  search_author
  elif [ &quot;$Author&quot; == &quot;&quot; ];
  then
  search_title
  else
  search_both
  fi
  </code></pre>
  <p>So the format of books.txt is <code>title:author:price:quantity:sold</code>
  Here is a sample of input if anyone would like to see:</p>
  <blockquote>
  <p>Lego Wars VI – Lego Legacy:Lego Company:$15.98:20:15</p>
  <p>Lego Wars VI – Return of the Lego:Fake Company:$8.05:30:20</p>
  <p>C++ for noobs:John Scissorhands:$15.01:10:5</p>
  <p>Java for noobs:Mary Scissorhands:$16.02:20:15</p>
  <p>VB.NET  for noobs:Edward Scissorhands:$17.03:30:25</p>
  </blockquote>