This page demistrates the Unix grep command and how to use it with it's options.

Code Output

-b option

         Displays the block number at the begining of each line.

Output

-c option

         Displays the number of matched lines.

Output

-h option

         Displays the matched lines, but does not display the filenames.

Output

-i option

         This tells the command to ignore case senstivity.

Output

-l option

         Displays the filenames but does not display the matched lines.

Output

-n option

         Displays the matched lines and their numbers.

Output

-v option

         Displays all the lines that DO NOT match.

Output

-w option

         This tells the command to match the whole word.

Output

. option

         This tells the command to match any individual character instance, execpt for the "new line" character, this can be very useful if used in the right combination with other grep options.

Output

* (wildcard)

         This tells grep that the letter or number can be anything. For example the user may put, "grep my*" that looks for any word that begins with "my", in other words, grep is looking for any number and combinations of letters after "my". The wildcard is usually used in conjunction with the "." . If the user puts, "grep *my" grep will look for any word that has "my" in the end of the word, examples right.

Output

[] range

         Brackets symbolize a range and this range may be numbers or letters. For example, if the user uses this command "grep [a-z].*ay" grep will look for any words that begin with a through z followed by any combination of letters and ends in "ay." The user may also put in letters that they desire to check for. For example, [aeiou], which will check for all lower case vowles, [AaEeIiOoUu] which will check for both upper and lower case vowles, or [a-z] which will look for all lower case letters starting at "a" and ending with "z".

Output

^ (caret)

         This character means the "beginning of the line" and will only match lines that begin with the character that follows the caret.

Output

$

         This character, which is a regular expression has the search stop at the end of the line.

Output