^ Match At The Beginning Of A Line

^ Match At The Beginning Of A Line

===> grep '^No' fortunes

Now is the time for all good men to come to the aid of their country.

No one can fell as helpless as the owner of a sick goldfish.

===> grep '^stu0' /etc/passwd

stu01a:*:501:501:Student Account:/u/students/stu01a:/bin/ksh

stu02a:*:502:502:Student Account:/u/students/stu02a:/bin/ksh

stu03a:*:503:503:Student Account:/u/students/stu03a:/bin/ksh

stu04a:*:504:504:Student Account:/u/students/stu04a:/bin/ksh

stu05a:*:505:505:Student Account:/u/students/stu05a:/bin/ksh

stu06a:*:506:506:Student Account:/u/students/stu06a:/bin/ksh

stu07a:*:507:507:Student Account:/u/students/stu07a:/bin/ksh

stu08a:*:508:508:Student Account:/u/students/stu08a:/bin/ksh

stu09a:*:509:509:Student Account:/u/students/stu09a:/bin/ksh

Previous slide Next slide Back to the first slide View Graphic Version

Notes:

In the first example: we’re matching those lines match the String “No” at the beginning of the line. Lines 21 and 29 satisfies this match from the fortunes file.

In the second example: were matching those lines in /etc/passwd file that begins with the character string “stu0”.

The capability to match at the beginning of a line is very powerful. Think of the possibility of needing to match header records; where the first set of characters at the beginning of the line will designate the record type.