From owner-freebsd-questions Sat Nov 10 7:39:18 2001 Delivered-To: freebsd-questions@freebsd.org Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by hub.freebsd.org (Postfix) with ESMTP id 0B9D937B422 for ; Sat, 10 Nov 2001 07:39:13 -0800 (PST) Received: from hades.hell.gr (patr530-a008.otenet.gr [212.205.215.8]) by mailsrv.otenet.gr (8.11.5/8.11.5) with ESMTP id fAAFd7B09610; Sat, 10 Nov 2001 17:39:07 +0200 (EET) Received: (from charon@localhost) by hades.hell.gr (8.11.6/8.11.6) id fAAFWtJ12541; Sat, 10 Nov 2001 17:32:55 +0200 (EET) (envelope-from charon@labs.gr) Date: Sat, 10 Nov 2001 17:32:54 +0200 From: Giorgos Keramidas To: Odhiambo Washington Cc: questions@freebsd.org Subject: Re: Help with AWK Message-ID: <20011110153254.GA12138@hades.hell.gr> References: <20011109194842.E27386@ns2.wananchi.com> <3BEC628A.5050005@verizon.net> <20011110094234.B1578@ns2.wananchi.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="tThc/1wpZn/ma/RB" Content-Disposition: inline In-Reply-To: <20011110094234.B1578@ns2.wananchi.com> User-Agent: Mutt/1.3.23.1i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --tThc/1wpZn/ma/RB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Odhiambo Washington wrote > * Simon Morton [20011110 02:17]: > | If I understand correctly, the following should do it > | > | awk -F: '$4==40{printf "^%s@.*\\.wananchi.com$:%s$:%s/:\n",$1,$3,$2;}' > > Hello Simon, > > That is not it ;). That line gives the following > > #^user@.*\.wananchi.com3552YZb2gtYJeEZ1Y/ > > What I want (from master.passwd) are the following fields with the extra > > ^$1@.*\.wananchi.com$:$3:$2 > > $1 = login id > $2 = encrypted passwd > $3 = numerical UID > > All with colon as the separator. > > I need to extract those details for two groups of users - staff (GID==20) and wheel (GID==0), > all in one command, if possible. a) Use egrep to limit the lines of master.passwd that interest you. (Not that it makes a great difference, but this way you separate the problem in two smaller problems: selecting lines, and printing those we selected with a format). egrep -e '^[^:]*:[^:]*:[^:]*:(20|0):.*$' master.passwd b) Then print only those fields you're interested in with awk's printf(). awk '{printf "^%s@.*\\.wananchi.com$:%s:%s\n",$1,$3,$2}' Testing this on my machine prints: # egrep -e '^[^:]*:[^:]*:[^:]*:(20|0):.*$' master.passwd | \ awk -F: '{printf "^%s@.*\\.wananchi.com$:%s:%s\n",$1,$3,$2}' ^root@.*\.wananchi.com$:0:PASSWORD --tThc/1wpZn/ma/RB Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (FreeBSD) iD8DBQE77Uim1g+UGjGGA7YRAi/zAKCIwTDW1l/cje2QQ/nUithCBw8UEwCgsFmg jw/3bh9FsF5K/5M6JqmIHzo= =jq1+ -----END PGP SIGNATURE----- --tThc/1wpZn/ma/RB-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message