Faced with the task of using grep to find related strings in a target file located on a USB flash drive, with the strings located in a file in the local directory, I had success with
the first two scripts, generalized to protect the innocent:
grep -f Pattern-File-A.txt /home/george/FlashDrive/...4 steps.../Target-File-A.txt > Output-File-A.txt grep -f Pattern-File-B.txt /home/george/FlashDrive/...4 steps.../Target-File-B.txt > Output-File-B.txt
These worked fine, with a satisfying number of matches.

Continuing, I used a similar script with the same path length from a third pattern file to the second target file, but the output file turned out to be identical to the input target
file, with zero matches.

My non-geek workaround was simply to move the target file into the working directory,
whereupon I met with success:
grep -f Pattern-File-C.txt Target-File-B.txt > Output-File-C.txt
The output was clean, with nothing irrelevant.

Target file sizes were 32.2MB, 63.5MB, and 63.5MB (the last two being the same file).
The Pattern files contained 385, 155, and 232 strings, respectively.
The successful output files included about 5500, 4000, and 600 matches, respectively.

There were no other scripts running during this exercise. The scripts each took a small
fraction of a second CPU time, even the unsuccessful one.
8GB RAM, 18GB swap, T420 ThinkPad

George Langford

Reply via email to