Skip to main content
1 of 3
Azim
  • 133
  • 1
  • 5

How can I loop through lines of a file and find files matching each line?

In a BASH shell, I would like to take the lines of a file (eg pattern.txt) and find the files on my system whose names contain the patterns in each line of my file. So, I have the following for loop

for pp in `cat pattern.txt`; do find ./ -iname "*${pp}*" -print0; done

which doesn't find any files when if the first line in pattern.txt doe exist. So how can I fix the above command line?

Azim
  • 133
  • 1
  • 5