8.2. grep and regular expressions
Using regular expressions we can now apply some rules to our pattern matching and be more selective about the information we want extracted. When we are using regular expressions it’s always a good idea to use single quotes, as this stops any special pattern you use in grep from being interpreted in strange ways by the command shell.
8.2.1. Pattern ranges
Suppose we wanted to get all the city locations that were either a 483 or 484 code. From the last chapter we know by using the [ ] brackets that we can specify a range of characters; here we specify that this will start with 48 and end with 3 or 4, thus extracting 483 or 484.
$ grep '48[34]' data.f 483 Sept 5AP1996 USP 65.00 LVX2C 189 484 nov 7PL1996 CAD ...
Get Linux and Unix Shell Programming 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.