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

    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Reverse parts of a string?


    Hello all,

    Wondering if anyone can help me out.

    Trying to cut the names out of the /etc/passwd file so that they can be displayed first then last name. I cut them out and put them into variables but cant get them to display side by side after cutting. Anyone able to help a newbie?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,436
    Rep Power
    1688
    So many ways ...

    Code:
    echo "$first $last"
    Code:
    echo -e "first\c"
    echo "$last"
    Code:
    awk -F: '{print $5}' /etc/passwd | awk '{print $2,$1}'
    Code:
    awk -F: '{split($5,names," "); print names[2],names[1]}' /etc/passwd
    Last edited by SimonJM; February 10th, 2011 at 05:55 AM. Reason: Correct syntax error
    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

IMN logo majestic logo threadwatch logo seochat tools logo