The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
shell script to search content of file with timestamps in the directory psychobeauty Shell Programming and Scripting 10 04-21-2008 05:37 AM
Shell script for text extraction from a file vignesh53 Shell Programming and Scripting 3 02-05-2008 08:16 AM
search for the contents in many file and print that file using shell script cdfd123 Shell Programming and Scripting 3 10-07-2007 10:17 PM
Shell script to return all the ID's from file based on the distribution ID search kumbhatalok UNIX for Dummies Questions & Answers 1 10-06-2006 12:53 PM
Korn Shell Script - Read File & Search On Values run_unx_novice Shell Programming and Scripting 2 06-15-2005 07:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-03-2007
imeadows imeadows is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 2
Red face Shell script to search for text in a file and copy file

Compete noob question....

I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory

help please
  #2 (permalink)  
Old 08-03-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
this will list all files in the given directory that contain the given string:
Code:
find /path/to/dir/ * | xargs grep abcde1234 | cut -d ":" -f1 | uniq
remaining is left for you to do
  #3 (permalink)  
Old 08-03-2007
imeadows imeadows is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 2
Thanks, have knocked this script up, what do you think
Code:
#!/bin/bash
files="$(find /opt/efx/ian/original | xargs grep abcdef123 | cut -d ":" -f1 | uniq)"
echo $files
for X in $files
do
cp $X /opt/efx/ian/copied
done

Last edited by Yogesh Sawant; 04-21-2008 at 12:50 AM.. Reason: added code tags
  #4 (permalink)  
Old 08-03-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Code:
egrep -l 'abcde1234' * | while read mFile
do
  cp ${mFile} /opt/efx/ian/copied
done
  #5 (permalink)  
Old 08-03-2007
quintet quintet is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 94
alternatively u can do like this

Code:
find /opt/efx/ian/original  -name '*' -exec grep -l "abcde1234" {} \; -exec cp {} /opt/efx/ian/copied \;

Last edited by Yogesh Sawant; 04-21-2008 at 12:49 AM.. Reason: added code tags
  #6 (permalink)  
Old 03-13-2008
kja328 kja328 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1
question

what type of files will this work on ? I have a need for this script to find terms in documents such as word and excel spreadsheets.
  #7 (permalink)  
Old 04-19-2008
psychobeauty psychobeauty is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 17
if u want to input in each time what the script to find u???
what do u change??

Last edited by psychobeauty; 04-19-2008 at 06:30 PM..
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0