Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-26-2012, 01:27 PM
|
#1
|
LQ Newbie
Registered: Aug 2012
Posts: 4
Rep: 
|
grep stdout to file and stderr to another file
I want output to go to one file and errors to go to another file. This works, however as the command stands right now, it doesn't return to the command line when terminated. thanks.
grep -r -n 'this*' /* >output.txt 2>errors.txt
|
|
|
08-26-2012, 02:44 PM
|
#2
|
Member
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 572
Rep: 
|
When terminated or when complete? It seems to work ok for me. Are you sure you want the /* and not ./*?
|
|
|
08-26-2012, 02:56 PM
|
#3
|
Member
Registered: Dec 2007
Location: India
Distribution: fedora 11
Posts: 64
Rep:
|
Hello,
May be you can try this one
grep -r -n 1>output.txt 2>errors.txt
Regards,
maniannam
|
|
|
08-26-2012, 03:05 PM
|
#4
|
LQ Newbie
Registered: Aug 2012
Posts: 4
Original Poster
Rep: 
|
Quote:
Originally Posted by devnull10
When terminated or when complete? It seems to work ok for me. Are you sure you want the /* and not ./*?
|
I did want to search entire root. The command does what it's suppose to do, but it does not seem to terminate as it doesn't return the command prompt back to me without hitting Ctrl-c.
|
|
|
08-26-2012, 03:26 PM
|
#5
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
Doing a recursive grep on the ENTIRE filesystem will take a long time...are you sure it isn't still running when you're hitting Ctrl+C? Try running it on a small directory with only a few files and see what happens.
|
|
1 members found this post helpful.
|
08-26-2012, 03:36 PM
|
#6
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
All that, and grepping certain "files" seems to never return. I'd recommend
a slightly different approach.
find / -type f | xargs -i grep -n 'this*' /* >output.txt 2>errors.txt
Cheers,
Tink
|
|
|
08-26-2012, 03:37 PM
|
#7
|
LQ Newbie
Registered: Aug 2012
Posts: 4
Original Poster
Rep: 
|
Quote:
Originally Posted by suicidaleggroll
Doing a recursive grep on the ENTIRE filesystem will take a long time...are you sure it isn't still running when you're hitting Ctrl+C? Try running it on a small directory with only a few files and see what happens.
|
You may be right. Or it may just hang because it's hit a socket or something else that I've been reading about. It runs fine on selected directories as you suggested, so I guess I should just limit my searches.
Thanks for your help. And you too maniannam.
I'll look into using xargs as well.
Last edited by hansfordmc; 08-26-2012 at 03:39 PM.
|
|
|
08-26-2012, 05:47 PM
|
#8
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Quote:
Originally Posted by hansfordmc
You may be right. Or it may just hang because it's hit a socket or something else that I've been reading about. It runs fine on selected directories as you suggested, so I guess I should just limit my searches.
Thanks for your help. And you too maniannam.
I'll look into using xargs as well.
|
The crucial bit there is the -type f switch to find, that will stop
you from grepping character devices, kernel RAM and other funky things from
which grep may not return ;}
Cheers,
Tink
|
|
|
All times are GMT -5. The time now is 07:39 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|