|
|
#1 |
|
Prospect
Join Date: Dec 2002
Location: Virginia
Posts: 2
|
simple use of grep & cp commands question
Hello,
A Unix question born of ignorance: I want to search through some files for a particular word and then copy those files to a new folder. So I tried.... grep -al theSearchWord sourceFolder | cp * targetFolder That didn't work. So I tried... cp 'grep -al theSearchWord sourceFolder' targetFolder That didn't work. I'm sure there's a simple answer, but I'm not familiar enough with Unix to find the simple answer. I'm running OSX10.3.9 with Terminal straight out the box. I wouldn't know, nor necessarily want to know, how to modify it. Thanks in advance... |
|
|
|
|
|
#2 | |||||||||||||||||||||||
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,935
|
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. |
|||||||||||||||||||||||
|
|
|
|
|
#3 |
|
Triple-A Player
Join Date: Jul 2002
Location: Virginia
Posts: 106
|
Thanks (the login name changes because it's linked somehow to the different computers that I use).
I tried the backtick instead the quote and it worked like a charm. |
|
|
|
|
|
#4 | |||||||||||||||||||||||
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,935
|
If I understand you correctly, you have more than one account on these forums. Your computer retains a cookie that automatically logs you in to the forums without asking for a username or password. It would be better if you decided which of your accounts you wanted to use and then used that account on all computers. All you would have to do is use the "logout" link that is at the top right of each page. Then log in using the account you have decided to use. If you have forgotten the password for an account, there is a provision to get a new password emailed to you - you'll see this if you mistype the password. |
|||||||||||||||||||||||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|