Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 10th, 2005, 7:49 AM   #1
dc6463
Newbie
 
Join Date: Jun 2005
Posts: 6
Rep Power: 0 dc6463 is on a distinguished road
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,
dc6463 is offline   Reply With Quote
Old Jun 10th, 2005, 8:50 AM   #2
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
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
skuinders is offline   Reply With Quote
Old Jun 10th, 2005, 12:52 PM   #3
Riddle
Programmer
 
Riddle's Avatar
 
Join Date: May 2005
Location: Nar Shaddaa
Posts: 42
Rep Power: 0 Riddle is on a distinguished road
Send a message via ICQ to Riddle Send a message via AIM to Riddle Send a message via MSN to Riddle
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.

Last edited by Riddle; Jun 10th, 2005 at 12:57 PM.
Riddle is offline   Reply With Quote
Old Jun 10th, 2005, 1:54 PM   #4
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to 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
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Jun 10th, 2005, 7:22 PM   #5
Riddle
Programmer
 
Riddle's Avatar
 
Join Date: May 2005
Location: Nar Shaddaa
Posts: 42
Rep Power: 0 Riddle is on a distinguished road
Send a message via ICQ to Riddle Send a message via AIM to Riddle Send a message via MSN to Riddle
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.
Riddle is offline   Reply With Quote
Old Jun 12th, 2005, 9:34 AM   #6
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
right on, i'll talk to K to see if we can clear the confusion up.
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Jun 13th, 2005, 2:55 AM   #7
dc6463
Newbie
 
Join Date: Jun 2005
Posts: 6
Rep Power: 0 dc6463 is on a distinguished road
Sorry for not being more specific. I meant *nix.

Thanks for the help!
dc6463 is offline   Reply With Quote
Old Jun 13th, 2005, 4:21 AM   #8
dc6463
Newbie
 
Join Date: Jun 2005
Posts: 6
Rep Power: 0 dc6463 is on a distinguished road
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
dc6463 is offline   Reply With Quote
Old Jun 13th, 2005, 12:06 PM   #9
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
back sure they're back hashes not just single appostraphes
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Jun 14th, 2005, 11:06 AM   #10
dc6463
Newbie
 
Join Date: Jun 2005
Posts: 6
Rep Power: 0 dc6463 is on a distinguished road
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 1:33 PM.
dc6463 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:59 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC