awk command | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

awk command

Shell Programming and Scripting


Tags
awk

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-13-2012
prabhu_kumar prabhu_kumar is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 1 June 2012, 12:39 AM EDT
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
awk command

Hi I am a starter to unix

my sample file contains following lines


Code:
prabhu kumar
ram saksena
sam saxena

now when I use the following command


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

I am getting o/p as


Code:
ram saksena 
sam saxena

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

kindly clarify ?

Last edited by Scrutinizer; 05-14-2012 at 02:36 AM..
Sponsored Links
    #2  
Old 05-14-2012
guruprasadpr's Avatar
guruprasadpr guruprasadpr is offline Forum Advisor  
Shrink...ing
 
Join Date: Jun 2009
Last Activity: 23 October 2014, 2:53 AM EDT
Location: India
Posts: 675
Thanks: 30
Thanked 215 Times in 214 Posts
Hi

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

Guru.
The Following User Says Thank You to guruprasadpr For This Useful Post:
prabhu_kumar (05-14-2012)
Sponsored Links
    #3  
Old 05-14-2012
prabhu_kumar prabhu_kumar is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 1 June 2012, 12:39 AM EDT
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
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
    #4  
Old 05-14-2012
guruprasadpr's Avatar
guruprasadpr guruprasadpr is offline Forum Advisor  
Shrink...ing
 
Join Date: Jun 2009
Last Activity: 23 October 2014, 2:53 AM EDT
Location: India
Posts: 675
Thanks: 30
Thanked 215 Times in 214 Posts
Hi



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

Guru.
Sponsored Links
    #5  
Old 05-14-2012
mirni mirni is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 2 October 2014, 3:08 AM EDT
Posts: 686
Thanks: 51
Thanked 178 Times in 171 Posts
Or

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

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing command output from one command to the next command in cshell kaaliakahn UNIX for Dummies Questions & Answers 2 02-10-2012 04:59 PM
unix command : how to insert text at the cursor location via command line? xib.be UNIX for Advanced & Expert Users 0 12-22-2010 05:45 PM
Need help! command working ok when executed in command line, but fails when run inside a script! 4dirk1 Shell Programming and Scripting 4 12-02-2010 05:47 AM
problem with output of find command being input to basename command... new_learner UNIX for Dummies Questions & Answers 2 12-14-2008 01:56 AM
awk/sed Command : Parse parameter file / send the lines to the ksh export command rajan_san Shell Programming and Scripting 4 11-06-2008 12:29 PM



All times are GMT -4. The time now is 09:54 AM.