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.
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.
The easiest way is to use curl
with the option -s
for silent:
curl -s http://somepage.com | grep whatever
curl
ing http://superuser.com/questions/431581
. For whatever reason I tested it with this particular URL and got no output. Dunno what I'm missing.
-L
switch.
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.
-q
, there is no error message.
If you are looking to grep or pipe headers, they are standard directed to stderr so you need to redirect them. Eg:
wget -O - http://example.com/page.php > /dev/null 2>&1 | grep HTTP
This bug was in v1.12.1 fixed in another version. Currently I use v1.15 and it works as expected.
The wget
writes its output to stderr
not to stdout
, so one needs to redirect the stderr
to stdout
:
wget -q -O - url 2&>1 | grep keyword