Regex1 - The beginnings

Start and end of lines:

^ to indicate the start of a line. This finds all lines beginning with 'dog'

egrep '^dog' file.txt

This will find lines beginning dog, dogbert, doggydogdog

And just so you know, the '^' is a regular expression 'metacharacter', while 'dog' consists of 'literal' characters.

$ indicates the end of the line, so this will find lines only consisting of 'dog':

egrep '^dog$' file.txt

Good eh?

Tags: regex