From owner-freebsd-questions Thu May 17 18: 6:28 2001 Delivered-To: freebsd-questions@freebsd.org Received: from guru.mired.org (okc-65-26-235-186.mmcable.com [65.26.235.186]) by hub.freebsd.org (Postfix) with SMTP id 3344C37B422 for ; Thu, 17 May 2001 18:06:24 -0700 (PDT) (envelope-from mwm@mired.org) Received: (qmail 24142 invoked by uid 100); 18 May 2001 01:06:23 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15108.30095.521591.799161@guru.mired.org> Date: Thu, 17 May 2001 20:06:23 -0500 To: Lucas Bergman Cc: questions@freebsd.org Subject: Re: Help w/ Awk In-Reply-To: <108340844@toto.iv> X-Mailer: VM 6.90 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: X-Loop: FreeBSD.ORG Lucas Bergman types: > > That's a simpler way of doing it, but doesn't accomplish what I'm trying to > > do. I'm trying to be able to loop through each user and get it's UID/GID and > > do stuff... > > > > My problem wasn't with my AWK statement, but with my for/next loop. > > > > For whatever reason (still unknown), the for Line in Password was failing, > > and was returning multiple lines, like there were EOL's embedded in the > > lines. > > You're right. The shell assumes the argument to 'for' is a list, a > string that it breaks into list elements at _any_ whitespace, not just > newlines. So, if your /etc/passwd lines had whitespace in them (and > they frequently do in the GECOS field), they would get broken in the > middle. > > A previous response already pointed out a solution, passing the file > to awk, which iterates over whole lines by default. You can use the > shell's 'read' also: > > while read line; do > # operate on "$line" > done > See sh(1). You can combine this with pipes to get AWK to parse your password line for you as well: awk -F: '{ print $1 " " $3 " " $4 } ' /etc/passwd | while read line do set -- $line # Operate with $1, $2 and $3 set to 1st, 3rd and 4th fields from passwd done http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message