LinuxQuestions.org
Register a domain and help support LQ
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, 02: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, 03:44 PM   #2
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 548

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

Rep: Reputation: 15
Hello,

May be you can try this one

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

Regards,
maniannam
 
Old 08-26-2012, 04: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, 04:26 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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, 04:36 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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, 04: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 04:39 PM.
 
Old 08-26-2012, 06:47 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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


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 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 05:28 PM
how to tell if a file is outputing to STDOUT or STDERR? xskycamefalling Linux - Newbie 5 05-15-2009 01:52 AM
Cannot redirect all stdout and stderr into file hawkgao Programming 2 05-12-2009 10:14 AM
send stderr to a file and also to stdout pranavchoudhary Linux - Newbie 7 08-25-2008 02:57 AM
redirecting stdout and stderr to a file Avatar33 Programming 4 03-12-2005 08:55 AM


All times are GMT -5. The time now is 02:27 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration