I would like to know which files contain a certain string. If I use 'grep "string" *' only the working directory is being searched. I also want to search the subdirectories. When I use 'find . -type f -print |xargs grep "string" > dev/null' I get the message 'xargs: missing quote?'. What's up?
Should I use another command?
However, this will only find you the filenames that contain the string. It will not search for the string <I>within</I> the file, which is what the original poster was asking about.
Location: Asia Pacific, Cyberspace, in the Dark Dystopia
Posts: 19,118
Thanks Given: 2,351
Thanked 3,359 Times in 1,878 Posts
Doing a find and then greping will certainly find the string within a string (in the file name) and works much better and faster. You are right PxT, this will not search the string within the file.
You will find a zillion occurances of the string 'lib' within a string. Here is a small sample and I've not even refined the grep or egrep (and just captured small output).
Yes, it does not search the actual file. I normally use PERL for that and not xargs. For some strange reason, xargs and I don't gel.... when I have to search files and strings within lots of files I use command line PERL.
Originally posted by PxT Which version of Unix does this work on? I have never encountered a grep that works like this. A portable solution is:
find . -exec grep string {} /dev/null \;
grep -r "string" * works pretty well on Linux(RH).
However this is not a comprehensive method. But I think this could be used for what poster is mentioned since he is using '*'(this cause grep read all files under each directory recursively).
But if he uses grep -r "www" html* will only recurse into subdirectories whose names starts with "html". so if there is a subdirectory whose name is not starts with "html" will be ignored even if it has the file that contain "www" string.
In COBOL, a hyphen can be used in a field name and in a specific program some field names would be identical to others except a suffix was added--sometimes a suffix to a suffix was used. For example, assume I am looking for AAA, AAA-BBB, and AAA-BBB-CCC and don't want to look at AAA-BBB-CCC... (7 Replies)
Guys,
i've got hundreds of C programs in my ~/devel/ directory and sub-directories. is there a way i can use grep -r followed by some zsh, sh, bash, to find some code that starts with "&foo" or something similar?
thanks in advance! (9 Replies)
I am making an eBook.
I am editing the html in BBedit.
I need to replace all <p class="s5"> with just a <p>.
How do I write this for GREP?
Thank you,
Abby (5 Replies)
Hello people!
I would like to create one script following this stage
I have one directory with 100 files
File001
File002
...
File100
(This is the format of content of the 100 files)
2012/03/10 12:56:50:221875936 1292800448912 12345 0x00 0x04 0
then I have one... (0 Replies)
Hi all ,
I'm new to unix
I have a checked project , there exists a file called xxx.config .
now my task is to find all the files in the checked out project which references to this xxx.config file.
how do i use grep or find command . (2 Replies)
Hi All,
Please tell me how can I Find a string using grep & print the line above or below that in solaris?
Please share as I am unable to use grep -A or grep -B as it is not working on Solaris. (10 Replies)
Hi All,
Please i need to know the difference between grep, egrep & grep -i when used to serach through a file.
My platform is SunOS 5.9 & i'm using the korn shell.
Regards,
- divroro12 - (2 Replies)
find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g'
this is simple logic to find and replace in multiple files & folders
Hope this helps.
Thanks
Zaheer (0 Replies)
Folks;
First about find:
when i run this:
find . -name '*log*' -mtime +10 -print | sed 's+^\./++;s+/.*++' | sort -u
i got list of log files but also get a directories (although directory names doesn't have "log" in it).
How can i exclude the directory from the output of this find command? ... (2 Replies)