Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2004
    Posts
    28

    Unanswered: 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??

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    who | grep '^aks '

  3. #3
    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

  4. #4
    Join Date
    Jan 2004
    Posts
    28
    who | awk '{print $1}' | grep -x 'aks'

    is the solution i found out

    thanks

  5. #5
    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 20:53.

  6. #6
    Join Date
    Aug 2004
    Posts
    10

    Grep

    plz try

    grep -w 'string pattern'

  7. #7
    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$/'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •