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
shell script to search content of file with timestamps in the directory psychobeauty Shell Programming and Scripting 10 04-21-2008 02:37 AM
Shell script for text extraction from a file vignesh53 Shell Programming and Scripting 3 02-05-2008 05: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 07: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 09:53 AM
Korn Shell Script - Read File & Search On Values run_unx_novice Shell Programming and Scripting 2 06-15-2005 04:20 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #8  
Old 04-20-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
kja328: grep and friends work on text files; as long as the words you want to look for are visible in the file with "less" or some such, it should still work. You might get accidental matches in Word and Excel files because they contain a lot of metadata, including stuff which used to be visible in the file but which was subsequently deleted.

psychobeauty: To put this in a script which accepts the regular expression to search for as an argument, use "$1" as a placeholder.

Shell scripts receive their positional arguments in $1, $2, $3 etc. $# will contain the number of arguments.

Code:
#!/bin/sh

case $# in 1) ;; *) echo "syntax: $0 regex" >&2 ; exit 2;; esac

find /opt/efx/ian/original -name '*' -exec grep -l "$1" {} \; -exec cp {} /opt/efx/ian/copied \;
A better script would also allow you to specify the path to search and the path to copy those files to.
Reply With Quote
Forum Sponsor
  #9  
Old 04-20-2008
drl's Avatar
drl drl is offline
Registered User
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 546
Hi.

See grep and binaries - Linux Forums for additional suggestions on search MS Word files with *nix utilities ... cheers, drl
Reply With Quote
  #10  
Old 1 Week Ago
Registered User
 

Join Date: Nov 2008
Posts: 1
Quote:
Originally Posted by Yogesh Sawant View Post
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
It's awesome..) works brilliant.

Thanks,
-Kiran
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:00 PM.


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

Content Relevant URLs by vBSEO 3.2.0