If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > how to grep for exact match

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-22-05, 03:40
calyan calyan is offline
Registered User
 
Join Date: Jan 2004
Posts: 28
how to grep for exact match

who | grep 'aks'

aks ttyp165 Sep 22 11:20
aks ttyp181 Sep 22 11:20
nkaks0 ttyp195 Sep 22 10:04
aks ttyp197 Sep 22 11:20
nkaks0 ttyp207 Sep 22 10:04
nkaks0 ttyp225 Sep 22 10:05

here there are some userids with letters aks but i need
exact match of aks, it should not include nkaks or mkaks etc

aks ttyp165 Sep 22 11:20
aks ttyp181 Sep 22 11:20
aks ttyp197 Sep 22 11:20

i also used grep -x it is not working?? how to solve this??
Reply With Quote
  #2 (permalink)  
Old 09-22-05, 04:28
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
who | grep '^aks '
Reply With Quote
  #3 (permalink)  
Old 09-22-05, 05:00
calyan calyan is offline
Registered User
 
Join Date: Jan 2004
Posts: 28
it fetches all the id which start with aks
but i need exact match

who | grep 'aks'

the user with userid aks

who | grep 'skr'

the user with userid skr

but here what happens
who | grep 'aks'

it gives other user id also that i dont need.
what is the solution
Reply With Quote
  #4 (permalink)  
Old 09-22-05, 05:23
calyan calyan is offline
Registered User
 
Join Date: Jan 2004
Posts: 28
who | awk '{print $1}' | grep -x 'aks'

is the solution i found out

thanks
Reply With Quote
  #5 (permalink)  
Old 10-02-05, 19:46
sycript sycript is offline
Registered User
 
Join Date: Oct 2005
Posts: 1
system failure: too many open pipes
w -h aks | awk ' { print $1 ; } '
oh ....

Last edited by sycript; 10-02-05 at 19:53.
Reply With Quote
  #6 (permalink)  
Old 10-05-05, 01:45
upsingh upsingh is offline
Registered User
 
Join Date: Aug 2004
Posts: 10
Grep

plz try

grep -w 'string pattern'
Reply With Quote
  #7 (permalink)  
Old 10-10-05, 06:32
test test is offline
Registered User
 
Join Date: Oct 2001
Posts: 46
Quote:
Originally Posted by calyan
who | awk '{print $1}' | grep -x 'aks'

is the solution i found out

thanks
Why use awk AND grep? Try...

who | awk '$1 ~ /^aks$/'
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On