Using ^ (Again) and $

Let's learn how to do more with REs, but match the start and end of a line with the ^ (again) and $ characters.

In order to uniquely match the years specified in the sample file, you can use the start-of-line and end-of-line regular expression characters to stop grep from matching items you do not want matched. For example, if my phone number was in the sample file, I would not want it specified and I can do that with REs.

The characters ^ and $ are commonly referred to as anchors. To anchor something would be to fix something firmly and stably. They will anchor a pattern to the start or end of a line. 1899 and 1999 are both at the beginning of a line so doing this will not be difficult, and will show you the way these REs ...

Get SAMS Teach Yourself Unix in 10 Minutes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.