Thread: Cut command

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Cut command


    Hi,
    I have a shell which shud display the name of the user so i use below grep to take their name

    [code]
    grep 'l828117' /etc/passwd
    [\code]

    l828117:0************:828117:357:Thelak Kumar ANBALAGAN, Etudes ACE-TP,,:/home/l828117:/usr/bin/ksh

    then i decided to display only the name so i used the below code
    Code:
    grep 'l828117' /etc/passwd|cut -d ' ' -f1,2,3
    but it displaying like below
    l828117:0************:828117:357:Thelak Kumar ANBALAGAN,

    i have to achieve only with name like Thelak Kumar ANBALAGAN

    how to do this.

    Regards
    Thelak
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    845
    Rep Power
    387

    Cool


    Try:
    Code:
    grep 'l828117' /etc/passwd|cut -d ':' -f5
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,443
    Rep Power
    1751
    Might also, using similar method, wish to 'parse out' the comment text from the comma onwards.

    Code:
    grep 'l828117' /etc/passwd|cut -d ':' -f5 | cut -d ',' -f1
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0
    thanks its working

IMN logo majestic logo threadwatch logo seochat tools logo