Trevor
Starfighter Starfighter
Starfighter
  • 289 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)
3 Replies
Chetan_Tiwary_
Community Manager
Community Manager
  • 268 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.

Gopinath_Pigili
Flight Engineer
Flight Engineer
  • 95 Views

Useful...!

Thanks for sharing..!!

Trevor
Starfighter Starfighter
Starfighter
  • 64 Views

Glad you found it useful!

I'm way behind in my series.  Got a lot of catching up to do.

Trevor "Red Hat Evangelist" Chandler
0 Kudos
Join the discussion
You must log in to join this conversation.