Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003

    Unanswered: VI / Regular Expression Help

    Hey hows it going.. I am new to Unix and working on a Solaris system. I need to take the etc/passwd file and seperate each line by the colons and then space it out evenly so all the lines form colums, so it looks something like this..

    Before Example:

    Donhoke:x:4454:44on Hooke:/var/adm:

    After Example:

    Donhoke 4454 44 Don Hooke /var/adm
    dfkfgfg 1138 512 Donh fgfghhj bin/ksh

    The user names start in column 0.
    The user ids end in column 24.
    The group ids end in column 34
    The real names start in column 40
    The shell starts in column 64

    Please give me some help or advice.. Thanks!!

  2. #2
    Join Date
    Jun 2002
    awk -F":" '{printf("%-10s%-10s%-10s%-10s\n",$1,$3,$4,$5)}' /etc/passwd

    Where '10' is the length of each individual column (I couldn't work out what widths you really wanted!)

  3. #3
    Join Date
    Oct 2003
    Hi ffresh12.

    do you need this ?

    > /etc/passwd.NEW
    cat /etc/passwd | awk ' BEGIN { FS=":"; OFS=":"}
    print $0 >> "/etc/passwd.NEW"
    print "User ",$1 >> "/etc/passwd.NEW"
    print "User-ID ",$2 >> "/etc/passwd.NEW"
    print "Group-ID ",$3 >> "/etc/passwd.NEW"
    print "User Name ",$4 >> "/etc/passwd.NEW"
    print "User Shell ",$5 >> "/etc/passwd.NEW"

    FS means the field seperator for input in awk
    OFS means the output field seperator ( the default in awk is a BLANK )

    That is what you get in /etc/passwd.NEW

    Donhoke:4454:44on Hooke:/var/adm
    User Donhoke
    User-ID 4454
    Group-ID 44
    User Name Don Hooke
    User Shell /var/adm

    Greetings from Germany
    Peter F.
    Last edited by fla5do; 10-06-03 at 16:15.

Posting Permissions

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