hayne
05-24-2005, 02:11 PM
cp 'grep -al theSearchWord sourceFolder' targetFolder
You are close. What you want is for the output of the 'grep' command to be used as the arguments to the 'cp' command. But you used single-quotes in the above. Single-quotes are used when you want something to be taken literally. To get something to be executed, you need to use back-quotes (`) - the character in the top left of standard US keyboards.
And of course you need to supply the names of the files to be searched, not the folder.
But since there is usually a limit to the length of an argument list, that won't work if the number of matching files gets large. If that happens you will need to learn about 'xargs'.
But there is another possible problem - if any of the filenames contain spaces. Again, we'll cross that bridge as we come to it.
You are close. What you want is for the output of the 'grep' command to be used as the arguments to the 'cp' command. But you used single-quotes in the above. Single-quotes are used when you want something to be taken literally. To get something to be executed, you need to use back-quotes (`) - the character in the top left of standard US keyboards.
And of course you need to supply the names of the files to be searched, not the folder.
But since there is usually a limit to the length of an argument list, that won't work if the number of matching files gets large. If that happens you will need to learn about 'xargs'.
But there is another possible problem - if any of the filenames contain spaces. Again, we'll cross that bridge as we come to it.
