LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Is getent a better option than parsing the /etc/passwd file through while loop (https://www.linuxquestions.org/questions/linux-newbie-8/is-getent-a-better-option-than-parsing-the-etc-passwd-file-through-while-loop-819723/)

grail 07-14-2010 10:18 AM

Nice change, but absolutely no need to go to other apps like sed or cut as awk can do it all:
Code:

#!/usr/bin/awk -f

BEGIN{ FS=":"}
{
        "groups "$1 | getline grps

        split(grps,grp," ")
        sec=gensub(".*"grp[3]" ","","1",grps)
        gsub(/ /,",",sec)

        print "RESULT_START __NAME__:"$1":USID:"$3":COMMENTS:"$5":HOME_DIR:"$6":SHELL:"$7":PRIMARY_GRP:"grp[3]":SECONDARY_GRPS:"sec":RESULT_END"
}



All times are GMT -5. The time now is 07:55 PM.