|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 ![]() |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
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 |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
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
|
||||
|
||||
|
Code:
egrep -l 'abcde1234' * | while read mFile
do
cp ${mFile} /opt/efx/ian/copied
done |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
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 |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
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.
|
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
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 | ||
|
![]() |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need to build Shell Script to search content of a text file into a folder consist several files | mukesh.baranwal | Shell Programming and Scripting | 3 | 09-16-2011 07:10 AM |
| shell script to take input from a text file and perform check on each servers and copy files | joseph.dmello | Shell Programming and Scripting | 0 | 02-04-2011 07:34 AM |
| Perl or Awk script to copy a part of text file. | asandy1234 | Shell Programming and Scripting | 26 | 11-06-2009 11:17 AM |
| To search a file for a specific word in a file using shell script | girish.raos | Shell Programming and Scripting | 8 | 09-01-2009 06:51 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 |
|
|