Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So I have a curl that is piped to a grep and a sed. Where would I apply the >/dev/null 2>&1 ?

curl www.site.com | grep stuff | sed "other stuff"

At the very end or after the curl?

share|improve this question
    
As I said, I want to silence the curl by directing its stdout output and stderr output to /dev/null. –  tzippy Jul 26 '12 at 22:13

3 Answers 3

Please be more specific what is the purpose of the command. I guess you want to use

curl -s www.site.com

to prevent the progress indication and other stuff. -s will perform the same action but silently

If you absolutely have to use >/dev/null 2>&1 i think i would redirect curl output to the file

curl www.site.com -o file.txt >/dev/null 2>&1
cat file.txt | grep stuff | sed "other stuff"   
share|improve this answer
    
Thanks. That's what I wanted to achieve. So out of curiousity: Where would the >/dev/null 2>&1 go? –  tzippy Jul 26 '12 at 22:17
1  
if you do curl www.site.com >/dev/null 2>&1 | grep stuff | sed "other stuff" the grep will receive nothing. If you do curl www.site.com >/dev/null 2>&1 | grep stuff | sed "other stuff" >/dev/null 2>&1 you will not see anything. –  mnmnc Jul 26 '12 at 22:21

Just explained a bit closer: >/dev/null redirects SDTOUT (standard output) to the "black hole", and 2>&1 appends STDERR (standard error output) to STDOUT so it also goes to Nirvana. This leaves nothing to display: normal output as well as errors are gone. So what you probably may want could be

curl -s www.site.com 2>/dev/null | grep stuff | sed "other stuff"

i.e. not redirecting STDOUT, just suppressing STDERR and telling curl to only show the indended content, then piping that to grep and finally to sed.

Take care to not introduce spaces between "2>", or the 2 would rather be interpreted as additional parameter to curl ;)

share|improve this answer

I ran across something similar recently and needed to time how long it took to load a particular page. I just used /dev/null as my output file and which let me get all the nice stats without printing any of the HTML.

curl www.google.com -o /dev/null

For my self, I also wrapped it in the time command for extra data

time (curl www.google.com -o /dev/null)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.