LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   grep stdout to file and stderr to another file (https://www.linuxquestions.org/questions/linux-newbie-8/grep-stdout-to-file-and-stderr-to-another-file-4175424089/)

hansfordmc 08-26-2012 01:27 PM

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

devnull10 08-26-2012 02:44 PM

When terminated or when complete? It seems to work ok for me. Are you sure you want the /* and not ./*?

maniannam 08-26-2012 02:56 PM

Hello,

May be you can try this one

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

Regards,
maniannam

hansfordmc 08-26-2012 03:05 PM

Quote:

Originally Posted by devnull10 (Post 4764758)
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.

suicidaleggroll 08-26-2012 03:26 PM

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.

Tinkster 08-26-2012 03:36 PM

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

hansfordmc 08-26-2012 03:37 PM

Quote:

Originally Posted by suicidaleggroll (Post 4764796)
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.

Tinkster 08-26-2012 05:47 PM

Quote:

Originally Posted by hansfordmc (Post 4764809)
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 09:32 AM.