From owner-freebsd-questions Wed May 16 11:49: 4 2001 Delivered-To: freebsd-questions@freebsd.org Received: from abby.skypoint.net (abby.skypoint.net [199.86.32.252]) by hub.freebsd.org (Postfix) with ESMTP id 78ADD37B42C for ; Wed, 16 May 2001 11:48:58 -0700 (PDT) (envelope-from pbiessener@hirshfields.com) Received: (from uucp@localhost) by abby.skypoint.net (8.8.7/jl 1.3) with UUCP id NAA11020 for freebsd-questions@freebsd.org; Wed, 16 May 2001 13:47:52 -0500 (CDT) Received: from spicer (spicer.hirshfields.com [192.168.195.244]) by fep.hirshfields.com (8.8.8/8.8.8) with SMTP id IAA15299 for ; Wed, 16 May 2001 08:48:27 -0500 (CDT) (envelope-from pbiessener@hirshfields.com) From: "C Peter Biessener" To: "FreeBSD Questions" Subject: RE: Help w/ Awk Date: Wed, 16 May 2001 08:58:36 -0700 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Importance: Normal Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I think your problem lies with the way for-do-done parses the input it is given. If you are comfortable with awk, I would write the entire script in awk - using the associative arrays that awk has, then in the END {} section print your output. I've never personally read the awk manpage, I use the O'Reilly book 'sed & awk' for a reference. e.g. $ awk -f _script.awk_ /etc/passwd > passwd.out with _script.awk_ something like this: BEGIN { FS=":" count = 1 } { user[count] = print $1 UID[count] = print $3 GID[count] = print $4 count += 1 } END { #print output here } -----Original Message----- From: owner-freebsd-questions@FreeBSD.ORG [mailto:owner-freebsd-questions@FreeBSD.ORG]On Behalf Of Don O'Neil Sent: Tuesday, May 15, 2001 6:10 PM To: freebsd-questions@FreeBSD.ORG Subject: Help w/ Awk 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; #!/bin/sh passwd=`cat /etc/passwd` for user in $passwd do username=`echo $user | awk 'BEGIN { FS=":" } END { print $1 }'` echo $username done Where am I going wrong with awk? Sometime the result of $username is the user name, but sometimes its another part of the entry in the file. I just want the user name stuck into username. Thanks! To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message