From owner-freebsd-questions@FreeBSD.ORG Wed Oct 8 19:16:22 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 65138106568E for ; Wed, 8 Oct 2008 19:16:22 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id A4C018FC17 for ; Wed, 8 Oct 2008 19:16:21 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (adsl58-6.kln.forthnet.gr [77.49.185.6]) (authenticated bits=128) by igloo.linux.gr (8.14.3/8.14.3/Debian-5) with ESMTP id m98JG4DI029253 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 8 Oct 2008 22:16:11 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.3/8.14.3) with ESMTP id m98JG4LB059287; Wed, 8 Oct 2008 22:16:04 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.3/8.14.3/Submit) id m98JG2Nl059280; Wed, 8 Oct 2008 22:16:02 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: Kalpin Erlangga Silaen References: <48EC410C.2030707@muliahost.com> Date: Wed, 08 Oct 2008 22:16:02 +0300 In-Reply-To: <48EC410C.2030707@muliahost.com> (Kalpin Erlangga Silaen's message of "Wed, 08 Oct 2008 12:11:40 +0700") Message-ID: <87wsgidhjh.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-MailScanner-ID: m98JG4DI029253 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.855, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.54, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: freebsd-questions@freebsd.org 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 19:16:22 -0000 On Wed, 08 Oct 2008 12:11:40 +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? You don't really need bash for this. Here's a sample awk script that should work: % cat -n /tmp/userlist.awk 1 #!/usr/bin/awk -f 2 3 { 4 print $1,"has uid",$2; 5 } % chmod 0755 /tmp/userlist.awk % cat /tmp/user-data admin 100 admin2 200 admin3 300 admin4 400 % /tmp/userlist.awk < /tmp/user-data admin has uid 100 admin2 has uid 200 admin3 has uid 300 admin4 has uid 400 %