I'm looking to seach all the files in a directory and sub-directories looking for a string. When the string is found, I want to display the filename and the entire line of that file that the string was found on.
what is the best way to do this ?? I've been playing around with awk, find, and grep with no luck. I am on HPUX 11.11
I didn't use the backsticks the first time.....but received another error when using them in which I needed to CNTL C out of.
I copied my cmd prompts this time. The first command shows the grep command working on 2 test files that I have. I also have a sub-directory in /home/mark with another test file that I want it to find............
[unix] mark[426]: pwd
/home/mark
[unix] mark[427]: grep -i 'monkey' *
find1.test:this line contains the word monkey.
find2.test:this line contains the words monkey and turtle.
grep: can't open oldetc
This code did serach the sub directories and display the line in the file......BUT now does NOT include the file name containing the string
[unix] mark[24]: pwd
/home
[unix] mark[25]: find . -name "*.c" -exec grep -i 'monkey' {} \;
find: cannot open ./mark/oldetc
this line contains the word monkey.
this line contains the words monkey and turtle.
[unix] mark[26]:
Oh, the -name "*" part is probably redundant. Try to leave it off and see if your find chokes.
It's surprising what people will get themselves into just so they don't have to download, build, and install GNU greputils. That would be my recommended solution for your inevitable follow-up problems.