Help - Search - Members - Calendar
Full Version: find command in loop routine - Need Help
Linuxhelp > Support > Programming in Linux
JClav
Greetings!

I've been trying to use find in a loop routine to get the path/filenames from a text file containing only filenames.
The text file has multiple filenames which correspond to files in various directories.

I can run a find / -name command on a single value but when I put it in a loop to iterate through all the filenames in a list I cannot get find to output the path/filename into a variable or another text file list.

This is the code I use:

while read xFile; do
echo $xFile
xFl=$(find / -name $xFile)
echo $xFl
done < filelist.txt


The result is that find stores a blank in the xFl variable which would mean that I would only be appending blanks to another text file list.

I need help on this and would appreciate advice and recommendations.

Thanks.
michaelk
filelist.txt contents:
file1
file2

while read xFile; do
echo $xFile
find / -name "$xFile" 2> /dev/null >> /output/file.txt
done < filelist.txt

Without the >> the output file will be overwritten on each iteration of the loop.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.