I am using grep -f to search through a directory for files that match the strings in the file I provide. Below is the command I am using
$find $(pwd) -type f |grep -f list.txt >result.txt
I am using the $pwd and find to display the complete path of the file when it is written to result.txt
When I run this command, I seem to return every file in the working directory and below.
List.txt contains (this is the “input”):
AAA_ERROR_2023_02_21.zip
ABA_ERROR_2023_02_23.zip
ACA_ERROR_2023_02_21.zip
AAA_LOG_2023_02_21.zip
Input is from an Excel list I copied and pasted from (I confirmed the files are there with a simple grep for the file name). Input in this sense is what is inside of list.txt
Output:
//returns almost everything in the sub directories
Expected output:
sampledirectory/parent/02/21/testfile_example_AAA_ERROR_2023_02_21.zip
sampledirectory/parent/02/23/testfile_example_ABA_ERROR_2023_02_23.zip
sampledirectory/parent/02/21/testfile_example_ACA_ERROR_2023_02_21.zip
sampledirectory/parent/02/21/testfile_example_AAA_LOG_2023_02_21.zip
I have tried |fgrep -wf list.txt and other variations with -o as well,
Is it possible the “_” in the file are messing up the pattern? Or is it possible my search list is not specific enough?
Any help is appreciated