![]() |
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, |
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 |
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.txtfind "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. |
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
|
Quote:
|
right on, i'll talk to K to see if we can clear the confusion up.
|
Sorry for not being more specific. I meant *nix.
Thanks for the help! |
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 |
back sure they're back hashes not just single appostraphes
|
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, |
| All times are GMT -5. The time now is 5:08 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC