Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 May 2001 21:33:40 -0500
From:      David Kelly <dkelly@hiwaay.net>
To:        "Don O'Neil" <don@whtech.com>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Help w/ Awk 
Message-ID:  <200105160234.f4G2Xec01850@grumpy.dyndns.org>
In-Reply-To: Message from "Don O'Neil" <don@whtech.com>  of "Tue, 15 May 2001 18:09:34 PDT." <MOBBIPGJKBNNPGLGMFHFIEIBHCAA.don@whtech.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
"Don O'Neil" writes:
> I'm trying to write a simple script to extract the user name, UID and GID of
> each user in the /etc/passwd file and I'm not quite sure what I'm doing
> wrong here.... here's a code snippet;

Let awk parse the entire passwd file. Don't bother launching awk for 
each and every line, its wasteful.

Try this on for size:

grumpy: {1013} cat junk.awk
#!/usr/bin/awk -f

BEGIN {
        FS =":"
}

{
        print $1
}
grumpy: {1014} ./junk.awk /etc/passwd
# $FreeBSD
#
root
toor
daemon
operator
...

Or better yet with a trival mod to drop the # lines:

grumpy: {1023} cat junk.awk 
#!/usr/bin/awk -f

BEGIN {
        FS =":"
}

!/^\#/ {
        print $1
}
grumpy: {1024} ./junk.awk /etc/passwd
root
toor
daemon
operator
...

-- 
David Kelly N4HHE, dkelly@hiwaay.net
=====================================================================
The human mind ordinarily operates at only ten percent of its
capacity -- the rest is overhead for the operating system.



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200105160234.f4G2Xec01850>