LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 02-24-2009, 04:39 PM   #1
traigo
Member
 
Registered: Nov 2008
Distribution: Ubuntu 9.10
Posts: 41

Rep: Reputation: 15
Grep on output of command returns all output


I've used grep before but this makes me feel like a total noob. I can run "ls -l | grep install" and it will list only the file install.log. So when I try to run "noip2 -S | grep IP" why do I get the full output of the command and not just the line with the IP Address?
 
Old 02-24-2009, 04:49 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

The stuff you see on the screen actually comes from *two* output streams: from both "stdout" (where "grep" expects to read from), and also from "stderr" (intended only for "error messages").

I'm guessing that your "noip2" either writes to stderr, or creates its own (third, separate!) output stream. Since grep only reads "stdout", you'd see *everything* from any stream that *isn't* "stdout".

'Hope that helps .. PSM

PS:
You can redirect different streams to a text file this way:

MYCMD > tmp.txt # redirects "stdout"
MYCMD 2> tmp.txt # redirects "stderr"
...
 
Old 02-24-2009, 05:15 PM   #3
traigo
Member
 
Registered: Nov 2008
Distribution: Ubuntu 9.10
Posts: 41

Original Poster
Rep: Reputation: 15
Great! Thanks! "noip2 -S 2>noip.txt" sent the output to the file noip.txt.
Also, a quick search on grep stderr showed how to redirect stderr to stdout
"noip2 -S 2>&1 | grep IP"
 
  


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
ps -eH | grep java output in a active passive clustered output johnkalikavunkal Linux - Server 2 01-30-2009 11:21 PM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
Need Grep command for the following output minil Programming 2 12-29-2005 07:49 AM
Need Grep command for the following output minil Programming 1 12-29-2005 06:51 AM

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

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