I am trying to fix a bash script that is supposed to:
- Go to a directory (RESULT_DIR)
- Find csv files that have matched names from a list file (Names.txt)
- Grep from patterns listed in (Patterns.txt) found in files from step 2
- Take that output and deposit it into a MatchingResults.txt
So far, I am getting the "argument list too long" error. But I am not sure how to fix this. I would appreciate some help on how to fix it, since I may have made mistakes I am not seeing.
#! /usr/bin/env bash
RESULT_DIR="$HOME/.../Results/"
NAMES="$HOME/.../Names.txt"
PATTERNS="$HOME/.../Patterns.txt"
cd "$RESULT_DIR" && grep -f "$PATTERNS" $(find $(cat "$NAMES").csv) >> MatchingResults.txt
Update: Here is what NAMES and PATTERNS look like so you can get a better idea of what I mean. Sorry this was lacking!
"NAMES"
"O60333"
"P52209"
"Q8N2Z9"
"O00230"
"O00273"
"O00468"
"O75381"
"Q86V15"
"E7ERA6"
"Q96HA4"
"K7EPZ7"
"H3BM07"
"H0YBK5"
"G8JLG8"
"Q13148"
"O00187"
and
"PATTERNS"
"R381P"
"T95A"
"E112K"
"R136G"
"R140Q"
"S149L"
"R173Q"
"S184A"
"E193G"
"V260M"
"P291L"
"H313Y"
"P328L"
Files in RESULT_DIR would have names such as "A12345.csv".
I would expect cat "$NAMES"
would output the contents of Names.txt as above so that they could be read line by line as arguments for grep -f patterns filestolookthrough
.
What I'm trying to do with $(find $(cat "$NAMES").csv)
is go through the names to match them in the results directory line by line to then match the grep -f pattern
solely in that particular matching file.
My error output only says line 8: /usr/bin/find: Argument list too long