Recursive grep
Hi
I'm trying to search for perl files that contain the string "Courses" and write an output to a text file containing filename and line where the text occurs. Doing this: grep Courses | find webct-3.8.0.27 -iname "*.pl" seems to find the right files, but it just stops after a little while. My question is how can I a) stop it from crashing b) get the other details to be written to a text file. Any help much appreciated :) ~James~ :newbie: |
Am I being daft, or should the command be the other way round? i.e. don't you need something like
find webct-3.8.0.27 -iname "*.pl" | grep Courses > OutputFile ? I may be mis-understanding your problem. :D |
You might try:
locate -r '\.pl$' | xargs grep 'Courses' > myfile.txt -r says expect a regular expression; xargs tells grep to use what locate gives it as arguments, i.e. do not simply look at the strings for Courses. locate may hide some files if you are not root. |
"grep -R" :D seams recurse enough for me ;)
and if you want to try some real exclusive commands: Code:
find . -iname "*.whatever" | while |
Re: Recursive grep
Quote:
If you use something like "find ... | grep " the output of 'find' will be passed to grep as if you've typed it yourself, and you can use "command < input.txt" as well. "command > file.txt" redirects the output to a file, and "command >> file.txt" adds the output to the end of the file. |
Thanks guys, I finally found my perfect command:
find webct-3.8.0.27/ -iname *.pl | xargs grep -i courses > Output.txt As you can see I've used some of the ideas and suggestions that just about all of you made and it was fun to learn a little more about those linux commands :) I would have said thanks sooner, but I've had a little bit of distraction come up on the side of this, so have only just got back around to sorting it out. Thanks! |
All times are GMT -5. The time now is 01:59 AM. |