December 1999
Beginner
528 pages
11h 10m
English
Grep also allows the use of international character pattern matching or class name form of pattern matching.
| Class | Regular expression equivalent |
|---|---|
| [[:upper:]] | [A-Z] |
| [[:lower:]] | [a-z] |
| [[:digit:]] | [0-9] |
| [[:alnum:]] | [0-9a-zA-Z] |
| [[:space:]] | same as a space or a tab |
| [[:alpha:]] | [a-zA-Z] |
Let’s use a couple of examples on our file to see how these work. We want to extract all the product codes that start with a ‘5’ and have at least two upper case letters following them. This will do it:
$ grep '5[[:upper:]][[:upper:]]' data.f
483 Sept 5AP1996 USP 65.00 LVX2C 189
483 may 5PA1998 USP 37.00 KVM9D 644
If we wanted to get all product codes that ended a ‘P’ or ‘D’ we could do ...
Read now
Unlock full access