cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Starfighter Starfighter
Starfighter
  • 73 Views

awk Tip - #5

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 "Red Hat Evangelist" Chandler
Labels (3)
1 Reply
Chetan_Tiwary_
Community Manager
Community Manager
  • 52 Views

@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 :

Chetan_Tiwary__0-1739963959636.png

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.

Join the discussion
You must log in to join this conversation.