title: Shell script to show frequency of each word in file and in a directory
body: <p>I came across a question in my interview</p>
  
  <blockquote>
    <p>Shell script to show frequency of each word in file and in a directory</p>
  </blockquote>
  
  <pre><code>A
      - A1
          - File1.txt
          - File2.txt
      -A2
          - FileA21.txt
      -A3
          - FileA31.txt
          - FileA32.txt
  B
      -B1
          - FileB11.txt
          - FileB12.txt
          - FileB13.txt
      -B2
          -FileB21.txt
  </code></pre>
  
  <p>I believe that I understood the question by understanding that Directories A and B are two separate directories with A1, A2 &amp; A3 being sub-directories of A, and B1 and B2 being sub-directories of B. So I answered like this.</p>
  
  <pre><code>Find . ‘\(-name “A” –and –name “B”\)’ –type f –exec cat ‘{}’ \; | awk ‘{c[$1]++} END {for (i in c) print i, c[i]}’
  </code></pre>
  
  <p>But still I got an feedback that the above script was not good enough. What's wrong in the given script?</p>