Yes it works. I actually stumbled upon this a few months ago.
I once pondered why this was. I get the same output whether I use > or >> to write out the file if it is outside the loop.
I believe that it is because the "> file.3" is outside of the loop so
ALL of the grepped data goes out together and is written ONCE and not each time the loop runs.
I believe that this is a little faster than writing each time the loop finishes, especially with 2 large files. I only had about 200 lines for file1, but file.2 had almost 1000 lines to be searched.
You would be right if I had put the > file.3 inside the loop, it would overwrite the file each time instead of appending as with >> file.3 would do.
So both of these are the same.
_________________________
for name in `cat file.1 `
do
grep $name file.2
done > file.3
_________________________
for name in `cat file.1 `
do
grep $name file.2 >> file.3
done
_________________________