awk command

Hi I am a starter to unix

my sample file contains following lines

prabhu kumar
ram saksena
sam saxena 

now when I use the following command

# awk  '/sa[kx]s*ena/'  sample 

I am getting o/p as

ram saksena 
sam saxena 

why is this happening ?
I am expecting only ram saksena but the terminal returns ram saksena along with sam saxena .
:wall:
kindly clarify ?:wall:

Hi

In the pattern /sa[kx]sena/, s indicates 0 or more occurrence of s. As per this definition, the output which you got is fine.

Guru.

1 Like

As you said here S* means 0 or more occurances of s
and what if I need to search 1 or more occurances of S ?
thanks a lot

Hi

$ awk '/sa[kx]s+ena/' file
ram saksena

Guru.

Or

awk '/sa[kx]ss*ena/' file