A file named "persons", contains the following names:
smith
chandler
jones
baker
russel
davidson
edwards
franks
zachary
wilson
turk
lee
harris
$ awk '/chandler|baker/' persons
- ONLY the lines with the names "chandler" and "baker" will be displayed
$ awk '/turk|davidson|russel/' persons
- ONLY the lines with the names "turk", "davidson", and "russel" will be
displayed
@Trevor valuable tip for learners especially the beginners who want to explore 'awk'.
in addition to that, here are some examples to extract more information from the same file with some matching patterns :
1. awk '/^s/' persons : aims to print the texts beginning with s.
2. awk '/a/' persons : aims to print the texts containing a.
3. awk '/n$/' persons : aims to print the texts which ends with n.
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.