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.
I have this running which works on each file individually:
awk '!/value1|value2/ && NF {print FILENAME " - " RS,$1}' RS="value" file1 > result.txt
But the output isn't correct, say, when applying it to each file in a directory using
find . -type f | awk ... file1 > result.txt
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.
File file1:
interface Vlan3990
ip address 172.17.226.23 255.255.255.254
File file2:
version 12.2
ip tacacs source-interface Loopback99
ip vrf test
description xx
interface Loopback99
description Management Loopback
interface Loopback100
shutdown
Output
find . -type f | xargs awk '!/description|shutdown/ && NF {print FILENAME " - " RS,$1}' RS="interface" | more
./file1 - interface Vlan3990
./file2 - interface version
I am not sure where the output 'interface version' is coming from...