0

How can i find all filenames that match a string in a list inside a file?

I have a list_file.txt with a list of email addresses each in a new line like this:

[email protected]
[email protected]
[email protected]
...

In the same directory i have many files that their filenames contains one of the email addresses of the list like this: [email protected], [email protected], etc.

¿How can i copy all matching files to a new directory?

1 Answer 1

1
for i in $(cat list_file.txt) ; do
  cp "email_$i.txt" newdirectory/
done

or if you want each match to be copied to its own separate directory:

for i in $(cat list_file.txt) ; do
  mkdir -p email_$i
  cp "email_$i.txt" "email_$i/"
done
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .