December 1999
Beginner
528 pages
11h 10m
English
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.
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 ...Read now
Unlock full access