LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 08-26-2012, 01:27 PM   #1
hansfordmc
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Rep: Reputation: Disabled
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
 
Old 08-26-2012, 02:44 PM   #2
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 572

Rep: Reputation: 120Reputation: 120
When terminated or when complete? It seems to work ok for me. Are you sure you want the /* and not ./*?
 
Old 08-26-2012, 02:56 PM   #3
maniannam
Member
 
Registered: Dec 2007
Location: India
Distribution: fedora 11
Posts: 64

Rep: Reputation: 16
Hello,

May be you can try this one

grep -r -n 1>output.txt 2>errors.txt

Regards,
maniannam
 
Old 08-26-2012, 03:05 PM   #4
hansfordmc
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by devnull10 View Post
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.
 
Old 08-26-2012, 03:26 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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.
Old 08-26-2012, 03:36 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
Old 08-26-2012, 03:37 PM   #7
hansfordmc
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
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.
 
Old 08-26-2012, 05:47 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by hansfordmc View Post
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
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] stderr stdout to a log file troubles metallica1973 Linux - Software 3 11-12-2011 04:28 PM
how to tell if a file is outputing to STDOUT or STDERR? xskycamefalling Linux - Newbie 5 05-15-2009 12:52 AM
Cannot redirect all stdout and stderr into file hawkgao Programming 2 05-12-2009 09:14 AM
send stderr to a file and also to stdout pranavchoudhary Linux - Newbie 7 08-25-2008 01:57 AM
redirecting stdout and stderr to a file Avatar33 Programming 4 03-12-2005 07:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:13 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
Open Source Consulting | Domain Registration