Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Bash / Shell Scripting (http://www.programmingforums.org/forum26.html)
-   -   script to copy files containing string (http://www.programmingforums.org/showthread.php?t=4390)

dc6463 Jun 10th, 2005 7:49 AM

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,

skuinders Jun 10th, 2005 8:50 AM

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

Riddle Jun 10th, 2005 12:52 PM

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
If it's in there once, it would return this.

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.

Dizzutch Jun 10th, 2005 1:54 PM

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

Riddle Jun 10th, 2005 7:22 PM

Quote:

Originally Posted by Dizzutch
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

Yeah, I don't associate the two either, but there have been posts about batch scripts in this section. I just decided I'd give the input. :P

Dizzutch Jun 12th, 2005 9:34 AM

right on, i'll talk to K to see if we can clear the confusion up.

dc6463 Jun 13th, 2005 2:55 AM

Sorry for not being more specific. I meant *nix.

Thanks for the help!

dc6463 Jun 13th, 2005 4:21 AM

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

Dizzutch Jun 13th, 2005 12:06 PM

back sure they're back hashes not just single appostraphes

dc6463 Jun 14th, 2005 11:06 AM

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