Super User is a question and answer site for computer enthusiasts and power users. 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 was wondering what does the <> do in a grep command

  • grep a b c , try to find a in file b and c
  • grep <html> foo?

What does the <> do? Find the HTML tags?

share|improve this question
up vote 3 down vote accepted

When inside quotes...

grep '<html>' foo

grep "<html>" foo does exactly that: find a <html> tag inside the foo file.

grep and egrep use POSIX regular expressions, which are described in the manual page of regex(7) – basic for grep, extended/modern for egrep. Neither version treats < or > specially.

When not inside quotes, however, it doesn't do anything useful.

grep <html> foo

grep < html > foo

Most commonly used shells will treat the above equally: run command grep with no arguments, reading from file named html, writing to file named foo. But this won't work, because there is no "pattern" to be given to grep, so you'll get an error message (and an empty foo file).

share|improve this answer
Since ricedragon is new to regular expressions, it is worth pointing out that grep '<html>' foo will not find <html lang="en">. It is often better to use an HTML parser for searching HTML. – RedGrittyBrick Oct 4 '11 at 9:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .