Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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
Was trying that option only. If you post that as an answer, I will accept it. – Ramesh Feb 8 '14 at 0:23
up vote 2 down vote accepted

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.

share|improve this answer

Your Answer


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.