I am using below snippet to search for a string (read from a file 'searchstring.out') in all locations (/) and then iterate over the files found to write the locations and the respective owner to an output file.
However, this doesn't work as I believe the find command doesn't exit's inside the shell script. The output file to which the find command redirects remains empty, even though the find command when run on the shell, returns rows.
for j in `cat searchstring.out`;
do
find / -name *$j* > $HOME/match.out
for k in match.out ;
do
owner=$(ls -l $k | awk '{print $3}')
echo "File found is:- $k"
echo "Owner is:- $owner"
done
done
Can someone advise how this can be made to work? How does the find command store all output to a file?
This looks much cleaner now. But when I try this, the search string is read from the output file correctly but seems the output from find is not piped to the second while loop. So, neither do I get the file found, nor the owner displayed on console.
When I run the find manually on shell (using same search string), it indeed returns the results.
As you said, a "\" after "|" does not make a functional difference.
Is your searchstring.out file okay?
Look at it with an editor on Unix.
Not created from WinDOS that appends invisible ^M (CR) characters?
(If yes, delete them.)
Add a test line with just an e . Then the find will run on *e* and certainly find many files.