Results 1 to 6 of 6
  1. #1
    Join Date
    May 2004
    Posts
    11

    Unanswered: cut and paste passwd file

    Hi all,

    How do i do the following using cut & paste:

    create a file from /etc/passwd in a format:

    userid:username:groupid

    e.g:
    0:root:0
    1:bin:1
    2:daemon:2
    3:adm:4

    i tried to cut the userid field with "cut -f 3 -d: > file1" but got the userid without ":" (deliminator) for making the first column in the new file.

    Thank you.

    Daryl

  2. #2
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    Hi Daryl Lim,
    I dont understand your question exactly. What is the output in file1 you want to have ?
    Greetings from germany
    Peter F.

  3. #3
    Join Date
    May 2004
    Posts
    11
    Hi Peter,

    I would like my file1 to be in the format of :

    userid:username:groupid



    regards,
    Daryl

  4. #4
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    Hi,
    do you mean this ?

    # this is an example from my passwd
    # support:x:1301:200upport-User:/usr2/support:/bin/sh
    # guest:x:1303:50:GastUser:/usr/guest:/bin/sh

    cat /etc/passwd | awk ' BEGIN { FS=":" }
    {
    print $3":"$1":"$4 > "file1"
    }'

    # and this will be the output in file1
    # 1301:support:200
    # 1303:guest:50
    Greetings from germany
    Peter F.

  5. #5
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    Quote Originally Posted by Daryl Lim
    i tried to cut the userid field with "cut -f 3 -d: > file1" but got the userid without ":" (deliminator) for making the first column in the new file.
    Hi, I read your question again and now I think to understand your problem.

    you get the delimiter ":" in file1 when you specify the second and more fields like this:"cut -f 3,4... -d: > file1"

    In your example is only one field. It is not necessary to use delimiters if you have only one field.
    Greetings from germany
    Peter F.

  6. #6
    Join Date
    May 2004
    Location
    New York
    Posts
    248
    You can use

    cat /etc/passwd | awk -F: '{print $1":"$2":"3}'

    where $fields will represend the order of the field in password file, separated by :

    cheers

Posting Permissions

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