O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.1. grep

The general format is:

grep [options] basic regular expression [file] 

where basic regular expression can be a string.

8.1.1. Please quote me

When you supply a string in a grep command it is good form to enclose it with double quotes. Like this: "mystring". There are two reasons for this. It stops the shell from misintepreting them as something else. Secondly, you may want to search for a string that contains a couple of words, like this: "jet plane". If you don’t surround the string with quotes it will think the word ‘plane’ is a file, and you’ll get error messages about non-existent files.

You should also use double quotes when using variables, like this: grep "$MYVAR" filename, if you do not you will get no data returned.

Use single ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required