From owner-freebsd-questions@FreeBSD.ORG Wed Oct 8 07:22:57 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 65D991065686 for ; Wed, 8 Oct 2008 07:22:57 +0000 (UTC) (envelope-from kalpin@muliahost.com) Received: from smtp.velo.net.id (mx1.velo.net.id [203.153.100.130]) by mx1.freebsd.org (Postfix) with ESMTP id 138EF8FC20 for ; Wed, 8 Oct 2008 07:22:47 +0000 (UTC) (envelope-from kalpin@muliahost.com) Received: from localhost (sniper.express.net.id [127.0.0.1]) by smtp.velo.net.id (Postfix) with ESMTP id E84BD120021; Wed, 8 Oct 2008 14:22:38 +0700 (WIT) X-Virus-Scanned: amavisd-new at velo.net.id Received: from smtp.velo.net.id ([127.0.0.1]) by localhost (seminyak.velo.net.id [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Inp34UgziNDb; Wed, 8 Oct 2008 14:22:37 +0700 (WIT) Received: from [203.153.106.5] (DALnet.tranquillity.se [203.153.106.5]) by smtp.velo.net.id (Postfix) with ESMTP id F113912001A; Wed, 8 Oct 2008 14:22:36 +0700 (WIT) Message-ID: <48EC5FC5.7030103@muliahost.com> Date: Wed, 08 Oct 2008 14:22:45 +0700 From: Kalpin Erlangga Silaen User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: Kalpin Erlangga Silaen , freebsd-questions@freebsd.org References: <48EC410C.2030707@muliahost.com> <20081008071156.GA94922@melon.esperance-linux.co.uk> <20081008072121.GB94922@melon.esperance-linux.co.uk> In-Reply-To: <20081008072121.GB94922@melon.esperance-linux.co.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Subject: Re: bash script on FreeBSD X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Oct 2008 07:22:57 -0000 Dear Frank, you are correct. Finally, I write my script using awk. Thank you Kalpin Erlangga Silaen Frank Shute wrote: > 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, > >