I have the following script which runs commands on each file in a directory to match for a specific pattern. It then prints the matching output to a .csv. I have the desired formatting, however each pattern that I am matching on is getting printed twice. Like this:
Match1
Match2
Match1
Match2
Piping uniq and sort into this script is not fixing the problem so I suspect my syntax is off. I have not been able to find a solution via Google or other answers thus far. Any help is appreciated, thanks!
#!/usr/bin/env bash
FILES=/Users/User1/Desktop/Folder/"*"
for f in $FILES
do
echo "Processing $f file..."
# take action on each file. $f store current file name
sed -n /"New Filters"/,/"Modified Filters"/p "$f" | grep -v -e 'Bugtraq ID:'
-e 'Common Vulnerabilities and Exposures:' -e 'Android' | grep -E '(^|[^0-9])
[0-9]{5}($|[^0-9])'| sed 's/:/,/1' >> NewFile.csv
echo "Complete. Check NewFile.csv"
done;
Sample Input: Expected Result is to extract text in bold
Filters
New Filters
Modified Filters (logic changes)
Modified
Filters (metadata changes only)
Removed FiltersFilters
New Filters:
29722: HTTP: Dragonfly Backdoor.Goodor Go Implant CnC Beacon 1Modified Filters (logic changes):
Text I don't wantModified Filters (metadata changes only):
Text I don't want