I wasn't surethink this does what you meant by finding CSV nameswant. HereI assume the $NAMES file are two variants you can modify:filenames that need the .csv extension added then each one is grepped for the patterns.
cd "$RESULT_DIR" && grep '\.csv$' "$NAMES" | xargs grep -Hf "$PATTERNS" >> MatchingResults.txt cd "$RESULT_DIR" && sed 's/$/.csv/' "$NAMES" | xargs grep -Hf "$PATTERNS" >> MatchingResults.txt Sorry for so many edits, I was working on something else while doing this. Hopefully something in here makes sense.