title: How To Run Multiple "awk" commands:
body: <p>Would like to run multiple "awk" commands in single script ..
  For example Master.csv.gz located at /cygdrive/e/Test/Master.csv.gz and 
  Input files are located in different sub directories like /cygdrive/f/Jan/Input_Jan.csv.gz &amp; /cygdrive/f/Feb/Input_Feb.csv.gz  and so on ..
  All input files are *.gz extension files.</p>
  
  <p>Below commands are working fine while executing command one by one:</p>
  
  <p>Command#1</p>
  
  <pre><code>awk ' BEGIN {FS = OFS = ","} FNR==NR {a[$2] = $0; next} ($2 in a) {print $0}'  &lt;(gzip -dc /cygdrive/e/Test/Master.csv.gz) &lt;(gzip -dc /cygdrive/f/Jan/Input_Jan.csv.gz) &gt;&gt;Output.txt
  </code></pre>
  
  <p>Output#1:</p>
  
  <pre><code>Name,Age,Location
  abc,20,xxx
  </code></pre>
  
  <p>Command#2</p>
  
  <pre><code>awk ' BEGIN {FS = OFS = ","} FNR==NR {a[$2] = $0; next} ($2 in a) {print $0}'  &lt;(gzip -dc /cygdrive/e/Test/Master.csv.gz) &lt;(gzip -dc /cygdrive/f/Feb/Input_Feb.csv.gz) &gt;&gt;Output.txt
  </code></pre>
  
  <p>Output#2:</p>
  
  <pre><code>Name,Age,Location
  def,40,yyy
  </code></pre>
  
  <p>cat Output.txt</p>
  
  <pre><code>Name,Age,Location
  abc,20,xxx
  def,40,yyy
  </code></pre>
  
  <p>Have tried below commands to run in via single script , got error:</p>
  
  <p>Attempt#1:  awk -f Test.awk</p>
  
  <p>cat Test.awk</p>
  
  <pre><code>awk ' BEGIN {FS = OFS = ","} FNR==NR {a[$2] = $0; next} ($2 in a) {print $0}'  &lt;(gzip -dc /cygdrive/e/Test/Master.csv.gz) &lt;(gzip -dc /cygdrive/f/Jan/Input_Jan.csv.gz) &gt;&gt;Output.txt
  awk ' BEGIN {FS = OFS = ","} FNR==NR {a[$2] = $0; next} ($2 in a) {print $0}'  &lt;(gzip -dc /cygdrive/e/Test/Master.csv.gz) &lt;(gzip -dc /cygdrive/f/Feb/Input_Feb.csv.gz) &gt;&gt;Output.txt
  </code></pre>
  
  <p>Error : Attempt#1:  awk -f Test.awk</p>
  
  <pre><code>awk: Test.awk:1:          ^ invalid char ''' in expression
  awk: Test.awk:1:          ^ syntax error
  </code></pre>
  
  <p>Attempt#2:  sh Test.sh</p>
  
  <p>cat Test.sh</p>
  
  <pre><code>#!/bin/sh
  awk ' BEGIN {FS = OFS = ","} FNR==NR {a[$2] = $0; next} ($2 in a) {print $0}'  &lt;(gzip -dc /cygdrive/e/Test/Master.csv.gz) &lt;(gzip -dc /cygdrive/f/Jan/Input_Jan.csv.gz) &gt;&gt;Output.txt
  awk ' BEGIN {FS = OFS = ","} FNR==NR {a[$2] = $0; next} ($2 in a) {print $0}'  &lt;(gzip -dc /cygdrive/e/Test/Master.csv.gz) &lt;(gzip -dc /cygdrive/f/Feb/Input_Feb.csv.gz) &gt;&gt;Output.txt
  </code></pre>
  
  <p>Error : Attempt#2:  sh Test.sh</p>
  
  <pre><code>Test.sh: line 2: syntax error near unexpected token `('
  </code></pre>
  
  <p>Desired Output:</p>
  
  <pre><code>Name,Age,Location
  abc,20,xxx
  def,40,yyy
  </code></pre>
  
  <p>Looking for your suggestions ..</p>
  
  <p><strong>Update#2-Month Name</strong>
  Ed Morton, Thanks for the inputs, however the output order are not proper , "Jan2014" is print on next line , please suggest      </p>
  
  <p>cat Output.txt:</p>
  
  <pre><code>Name,Age,Location
  abc,20,xxx
  Jan2014
  def,40,yyy
  Feb2014
  </code></pre>
  
  <p>Expected Output</p>
  
  <pre><code>Name,Age,Location
  abc,20,xxx,Jan2014
  def,40,yyy,Feb2014
  </code></pre>