title: Run on all files in a directory, treating each separately, using AWK
body: <p>I want to run an AWK script on each file in a directory, but the AWK command must run only within that file - that is, it searches between a defined RS and returns what it is supposed to, but I need it to stop when it reaches the end of one file, and begin again at the start of the next file.</p>
  
  <p>I have this running which works on each file individually:</p>
  
  <pre><code>awk '!/value1|value2/ &amp;&amp; NF {print FILENAME " - " RS,$1}' RS="value" file1 &gt; result.txt
  </code></pre>
  
  <p>But the output isn't correct, say, when applying it to each file in a directory using</p>
  
  <pre><code>find . -type f | awk ... file1 &gt; result.txt
  </code></pre>
  
  <p>How would I get it to look at each file individually, but append the results into the same file? I have no idea unfortunately. I guess it's by adding each file into a variable and having AWK look at that, but I am not sure how to do it.</p>
  
  <h3>File file1:</h3>
  
  <pre><code>interface Vlan3990
   ip address 172.17.226.23 255.255.255.254
  </code></pre>
  
  <h3>File file2:</h3>
  
  <pre><code>version 12.2
  ip tacacs source-interface Loopback99
  ip vrf test
   description xx
  interface Loopback99
   description Management Loopback
  interface Loopback100
   shutdown
  </code></pre>
  
  <h3>Output</h3>
  
  <pre><code>find . -type f | xargs awk '!/description|shutdown/ &amp;&amp; NF {print FILENAME " - " RS,$1}' RS="interface" | more
  ./file1 - interface Vlan3990
  ./file2 - interface version
  </code></pre>
  
  <p>I am not sure where the output 'interface version' is coming from...</p>