The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search for a string and copy the entire line forumthreads UNIX for Dummies Questions & Answers 1 06-22-2007 07:20 AM
Copy / string. Paulw0t Shell Programming and Scripting 6 03-10-2007 07:26 PM
Search a string from list of input files sivakumarvenkat UNIX for Dummies Questions & Answers 2 03-08-2006 02:08 PM
copy and rename list of files kinmak UNIX for Dummies Questions & Answers 7 02-27-2005 05:23 PM
find and copy string in a file vascobrito UNIX for Advanced & Expert Users 10 03-03-2004 10:14 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-28-2007
Registered User
 

Join Date: Feb 2005
Posts: 68
How to List and copy the files containing a string


I have more than 8000 files in a dir, I need to copy to other dir which containing the "sample"

I tried
grep -il "1189609240791-1268115603299237276@216.109.111.119 ' | cp /tmp/inv

Nothing is happening for long time for 100 file dir too,

Any one can help me?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-28-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,432
For filenames with no embedded spaces(or other pathological characters):

Code:
mv $(grep -l '1189609240791-1268115603299237276@216.109.111.119')  /tmp/inv
Otherwise write a loop.

Aah, and if you get "too many arguments",
use zsh/zargs

Last edited by radoulov; 09-28-2007 at 07:26 AM.
Reply With Quote
  #3 (permalink)  
Old 09-28-2007
Registered User
 

Join Date: Feb 2005
Posts: 68
Quote:
Originally Posted by radoulov View Post
For filenames with no embedded spaces(or other pathological characters):

Code:
mv $(grep -l "1189609240791-1268115603299237276@216.109.111.119 ')  /tmp/inv
Otherwise write a loop.

Aah, and if you get "too many arguments",
use zsh/zargs
Its not working...

ctlrws001[/tmp/inv1]$ cp $(grep -l "1190151616066-4284832706333417688@216.109.111.119') /tmp/inv/test
>
ctlrws001[/tmp/inv1]$ grep -l "1190151616066-4284832706333417688@216.109.111.119
>
Reply With Quote
  #4 (permalink)  
Old 09-28-2007
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,503
The quotes are mismatched.
Reply With Quote
  #5 (permalink)  
Old 09-28-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,432
Quote:
Originally Posted by reborg View Post
The quotes are mismatched.
Yep, corrected
Reply With Quote
  #6 (permalink)  
Old 09-28-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,432
Quote:
Originally Posted by redlotus72 View Post
Its not working...

ctlrws001[/tmp/inv1]$ cp $(grep -l "1190151616066-4284832706333417688@216.109.111.119') /tmp/inv/test
>
ctlrws001[/tmp/inv1]$ grep -l "1190151616066-4284832706333417688@216.109.111.119
>
Check the corrected version
Reply With Quote
  #7 (permalink)  
Old 09-28-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,432
Just curious, I tried this:
Code:
zsh 4.3.4% for i ({1..400000}) touch "$i".txt
Ctrl+C after a while.
Code:
zsh 4.3.4% rm *txt
zsh: argument list too long: rm
zsh 4.3.4% autoload zargs
zsh 4.3.4% zargs *txt rm --
zargs:168: subscript too big: 397905
zsh 4.3.4% while :;do rm *.txt([1,20000]);done
zsh: argument list too long: rm
The solution was:
Code:
while :;do rm *.txt([1,10000]);done
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0