From owner-freebsd-questions@FreeBSD.ORG Wed Oct 8 07:21:31 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A9AF3106569A for ; Wed, 8 Oct 2008 07:21:31 +0000 (UTC) (envelope-from frank@esperance-linux.co.uk) Received: from mailout.zetnet.co.uk (mailout.zetnet.co.uk [194.247.47.231]) by mx1.freebsd.org (Postfix) with ESMTP id 191D78FC17 for ; Wed, 8 Oct 2008 07:21:31 +0000 (UTC) (envelope-from frank@esperance-linux.co.uk) Received: from irwell.zetnet.co.uk ([194.247.47.48] helo=zetnet.co.uk) by mailout.zetnet.co.uk with esmtp (Exim 4.63) (envelope-from ) id 1KnTMP-0007NZ-04; Wed, 08 Oct 2008 08:21:29 +0100 Received: from melon.esperance-linux.co.uk (54-144.adsl.zetnet.co.uk [194.247.54.144]) by zetnet.co.uk (8.14.1/8.14.1/Debian-9) with ESMTP id m987LQMr014955; Wed, 8 Oct 2008 08:21:27 +0100 Received: by melon.esperance-linux.co.uk (Postfix, from userid 1001) id D64C6FCA4AD; Wed, 8 Oct 2008 08:21:21 +0100 (BST) Date: Wed, 8 Oct 2008 08:21:21 +0100 From: Frank Shute To: Kalpin Erlangga Silaen , freebsd-questions@freebsd.org Message-ID: <20081008072121.GB94922@melon.esperance-linux.co.uk> Mail-Followup-To: Kalpin Erlangga Silaen , freebsd-questions@freebsd.org References: <48EC410C.2030707@muliahost.com> <20081008071156.GA94922@melon.esperance-linux.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20081008071156.GA94922@melon.esperance-linux.co.uk> User-Agent: Mutt/1.4.2.3i X-Face: *}~{PHnDTzvXPe'wl_-f%!@+r5; VLhb':*DsX%wEOPg\fDrXWQJf|2\,92"DdS%63t*BHDyQ|OWo@Gfjcd72eaN!4%NE{0]p)ihQ1MyFNtWL X-Operating-System: FreeBSD 6.3-RELEASE-p2 i386 X-Organisation: 'http://www.shute.org.uk/' X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (zetnet.co.uk [194.247.46.1]); Wed, 08 Oct 2008 08:21:28 +0100 (BST) Cc: Subject: Re: bash script on FreeBSD X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Frank Shute List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Oct 2008 07:21:31 -0000 On Wed, Oct 08, 2008 at 08:11:56AM +0100, Frank Shute wrote: > > On Wed, Oct 08, 2008 at 12:11:40PM +0700, Kalpin Erlangga Silaen wrote: > > > > Dear all, > > > > I am going to extract field username and UID from /etc/passwd and passed > > into some scripts. Let say I got line > > > > admin 100 > > admin2 200 > > admin3 300 > > admin4 400 > > > > and then I want to echoing into screen: > > > > admin has uid 100 > > admin2 has uid 200 > > admin3 has uid 300 > > admin4 has uid 400 > > > > How do I make this with bash script? > > > > Thank you > > > > > > Kalpin Erlangga Silaen > > $ sed -e 's/\(admin[0-9]*\)\ \([0-9]*\)/\1 has uid \2/g' /etc/passwd > Correction: You can't use that on /etc/passwd directly. But assuming you've got a file already in the format you specified, then you can use it on that. If you want to grab the data directly from /etc/passwd then you'd be better off using awk(1). Regards, -- Frank Contact info: http://www.shute.org.uk/misc/contact.html