Pipe output of wget through grep using php url

Posted on 2011-10-12
Last Modified: 2012-05-12
I am trying to pipe the output of a wget command through grep. The url is a php file with parameters. I can do it as 2 separate commands but would like to combine them so I do not have to write the file to the disk.

This code does not work (the result is always unsuccessful) -
wget --output-file=wgetlogfile2.txt --O - http:/ | grep -qi STRING'

This code does work -  
wget --output-file=wgetlogfile2.txt --output-document=testdoc.html http:/
sleep 2
grep -qi 'STRING' testdoc.html
if [ $? -eq 0 ]                        

If I remove the "sleep" from the code that it works, it fails

Any ideas would be appreciated.
Question by:bsg999
    LVL 16

    Expert Comment

    Note special case hyphen after O means the document will be written to standard output:

    wget -qO-  http:/ | grep -qi 'STRING'

    Open in new window


    Author Comment


    I have that in option in my command."--O -".  I had a typo when I entered the question having put two dashes in front of the "O".  There is only one dash.

    I have resolved my problem.   I had to enclose the URL in quotes.

    Thanks for your comment.

    Accepted Solution

    I have resolved the issue by enclosing the URL in quotes.


    Author Closing Comment

    I did not assign an A since I should have found the solution before submitting the question.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
    Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now