I am extracting information from a website. I designed the code in VBA and found that it is taking too long to execute. So, I have decided to rewrite the code in Unix script. I am extracting a page information using curl command as below.

page="$(curl http://www.somesitename.com/)"

Now, the variable $page contains the entire page contents in a HTML format. I am looking for a particular div class in the web page.

I use the grep command as below.

output=$("$page"|grep "div class=\"my_class_name\"")

If I just use echo "$page"|grep "div class=\"my_class_name\"" I get the contents of div in the echo statement. However, as above when am trying to save it in a variable and printing, I am getting the entire HTML page contents as output.

I just need to check if the pattern "div class=\"my_class_name\" occurs in the page.

  • 1
    Will output="$($page|grep \"div class='my_class_name'\")" work. Encasing the entire command might do the trick
    – Jeight
    Feb 8 '14 at 0:20

Go ahead and try using the following:

output="$($page|grep \"div class='my_class_name'\")"

Encasing the entire command in quotes should do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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