A Quick Introduction to Unix/More grep examples

Beginning of line
A search can be constrained to find the string at the beginning of the line with the symbol ^. Example:

Finds the string A at the beginning of lines.

End of line
A search can be constrained to find the string at the end of the line with the symbol $. Example: Finds the string 5 at the end of lines.

Counting empty lines
The combination search string ^$ finds empty lines.

To match any single character
The meta-character . matches any single character except the end of line character.

Example
The input file contains these lines:

We search with

The results are

The first line doesn't match.

To match zero or more characters
The meta-character * matches zero or more occurences of the previous character.

Example
The input file bells containes these lines

We search with

The results are

Example
The input file is as the previous example. The . is used after the * to require at least a single character.

We search with

The results are

Contrast this with the previous example. Here, we match everything except be.

Example
The input file is as before.

We search with

The results are

Character lists
You can use a list of characters surrounded by [ and ] which will match on any single character in the list.

Example
The input file is lines:

we search with

The result is

Example
The input file is as before.

we search with

The result is