LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 10-02-2003, 04:58 AM   #1
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Rep: Reputation: 15
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~
 
Old 10-02-2003, 06:54 AM   #2
pavgust
Member
 
Registered: May 2003
Distribution: Debian
Posts: 40

Rep: Reputation: 15
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.
 
Old 10-02-2003, 07:13 AM   #3
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
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.
 
Old 10-02-2003, 07:40 AM   #4
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
"grep -R" seams recurse enough for me

and if you want to try some real exclusive commands:

Code:
find . -iname "*.whatever" | while
 read filename
do
  
  .. some commands with $filename

done
 
Old 10-02-2003, 07:46 AM   #5
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
Re: Recursive grep

Quote:
Originally posted by jimieee
a) stop it from crashing b) get the other details to be written to a text file.
crashing? Maybe "grep" is just a little buzzy.. You didn't specify any file names, so it's waiting for you to type them. Your machine hasn't crashed. it's just waiting for input. Press Ctrl+D to send the end-of-file marker, or press Ctrl+C to terminate the program.

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.
 
Old 10-06-2003, 11:13 AM   #6
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Original Poster
Rep: Reputation: 15
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
grep ?? can grep us variables? DaFrEQ Linux - Software 4 09-14-2005 01:22 PM
rm -r what is recursive wogga Linux - Software 3 05-28-2004 03:29 PM
What does rpm -qa |grep th* (as compared to rpm -qa |grep th) display? davidas Linux - Newbie 2 03-18-2004 02:35 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 04:11 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 12:38 PM


All times are GMT -5. The time now is 02:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration