![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jun 2005
Posts: 6
Rep Power: 0
![]() |
script to copy files containing string
i need a script to copy all files containing a certain string (in the file) to a directory. any help would be greatly appreciated.
thanks, |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4
![]() |
I'm on windows at work so I did this without being able to check it...
cp `grep -f *.txt -e stringpattern -l` the_dir
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand." - B. Russell http://web.bryant.edu/~srk2 |
|
|
|
|
|
#3 |
|
Programmer
|
Assuming you're on *nix, though.
lol, and here's the help I forgot to add (if you're using Windows): You can use the find command. Example, let's say that you're looking for the string lol!! in a file called lol.txt. find "lol!!" lol.txt find "lol!!" lol.txt ---------- LOL.TXT "lol!!" Unfortunately, I don't know if you can use a 'greater than' operator in batch files (if you could, you could use the /c switch to show you the count of lines containing it (example: 2)). If you can find a way to use the greater than operator, go for it. Last edited by Riddle; Jun 10th, 2005 at 1:57 PM. |
|
|
|
|
|
#4 |
|
Professional Programmer
|
I don't associate BASH/Shell scripting with Windows, but i think it would be a good idea to specify when posting threads in this forum in the future, unless we decide that BASH/Shell scripting also includes windows Batch
|
|
|
|
|
|
#5 | |
|
Programmer
|
Quote:
![]() |
|
|
|
|
|
|
#6 |
|
Professional Programmer
|
right on, i'll talk to K to see if we can clear the confusion up.
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Jun 2005
Posts: 6
Rep Power: 0
![]() |
Sorry for not being more specific. I meant *nix.
Thanks for the help! |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Jun 2005
Posts: 6
Rep Power: 0
![]() |
when i try:
cp `grep -f *.txt -e string -l` tmp i get this error: cp: grep -f *.txt -e string -l: No such file or directory |
|
|
|
|
|
#9 |
|
Professional Programmer
|
back sure they're back hashes not just single appostraphes
|
|
|
|
|
|
#10 |
|
Newbie
Join Date: Jun 2005
Posts: 6
Rep Power: 0
![]() |
ok, my mistake. got it.
works great, but copying the files in OS X changes the date modified for the files. any idea how to do this in with a windows batch file or even better with python? thanks again for the help, Last edited by dc6463; Jun 14th, 2005 at 2:33 PM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|