Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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'm trying to get a hang of grep. I've got the following command from a GeekLet script that someone made for getting the weather info off some website:

curl -s '' | grep '"content\|"remark\|span' || sed 's/<[^>]*>//g' | sed 's/]*>//g' | sed 's/&#176;/°/'

I'm not worried about the sed command right now. I know it clears up the output to be neatly formatted, but for now I'm just trying to figure out the grep command.

I have a couple of questions that none of the guides/manuals over there seem to have a clear answer for:

  1. What does the backslash (\) do over here?
  2. What do the pipes "|" in between do?
  3. Why is "content\|" in double quotes?

Also any other ideas/guides that you know of which touch upon parsing html content with grep?

share|improve this question

migrated from Dec 7 '12 at 9:22

This question came from our site for professional and enthusiast programmers.

up vote 3 down vote accepted
  1. What does the backslash (\) do over here?

    grep uses an "escaped" pipe (|) to mean logical OR. In other words, grep 'foo\|bar' means print any lines that contain either "foo" or "bar".

  2. What do the pipes "|" in between do?

    See answer to 1.

  3. Why is "content\|" in double quotes?

    It is not. The quotes are part of the pattern being searched for, the output of the curl command you give contains these lines:

    </title><meta http-equiv="Content-Language" content="en-us" /> 
    <div class="content">

    The quote (not quotes, the second " belongs to the next pattern, "remark) before the word "content" is there to make grep print only the second of the lines above. It is part of the actual search pattern: "content.

share|improve this answer
Thank you! That cleared it up. Also if someone else needs to know more about this I found a good grep resource here: – Sid Dec 8 '12 at 9:46

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.