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.

I have a html-page url and I want to grep it. How can I do it by wget someArgs | grep keyword?

My first idea was wget -q -O - url | grep keyword, but wget's output bypass grep and arise on the terminal in its original form.

share|improve this question
    
grep selects lines delimited by (e.g.) carriage return and linefeed characters, an HTML response doesn't have lines it has text with markup like <br> or <p> so the whole web-page could look like one line to grep –  RedGrittyBrick Jun 1 '12 at 19:44
1  
@RedGrittyBrick The OP's command works flawlessly for me. –  slhck Jun 1 '12 at 19:47
add comment

2 Answers

up vote 3 down vote accepted

The easiest way is to use curl with the option -s for silent:

curl -s http://somepage.com | grep whatever
share|improve this answer
    
@slhck: Both commands do exactly the same for me. –  Dennis Jun 1 '12 at 21:39
    
@Dennis Try curling http://superuser.com/questions/431581. For whatever reason I tested it with this particular URL and got no output. Dunno what I'm missing. –  slhck Jun 1 '12 at 21:45
    
@slhck: Curl doesn't follow redirects by default. It does with the -L switch. –  Dennis Mar 31 '13 at 20:15
    
@Dennis Didn't know what you were talking about without seeing the deleted comments – but yeah, that makes sense. Thanks for clearing it up. –  slhck Mar 31 '13 at 20:27
add comment

Keeping this around for the sake of completeness.

Your example should actually work. The syntax is correct, and here's a screencast I just took demonstrating it, with a good old GNU wget 1.13.4.

wget -q some-url -O - | grep something

So assume your pattern is wrong and grep will just output everything it got.

share|improve this answer
    
It could also be a typo in the URL. With -q, there is no error message. –  Dennis Jun 2 '12 at 0:44
add comment

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.