From owner-freebsd-questions@FreeBSD.ORG Thu Nov 22 18:25:03 2007 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 81D4D16A417 for ; Thu, 22 Nov 2007 18:25:03 +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 1249C13C448 for ; Thu, 22 Nov 2007 18:25:02 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (vader.bytemobile-rio.ondsl.gr [83.235.57.37]) (authenticated bits=128) by igloo.linux.gr (8.14.1/8.14.1/Debian-9) with ESMTP id lAMIOI7g029588 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 22 Nov 2007 20:24:31 +0200 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.2/8.14.2) with ESMTP id lAMIODsM004361; Thu, 22 Nov 2007 20:24:13 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.2/8.14.2/Submit) id lAMIODDq004360; Thu, 22 Nov 2007 20:24:13 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Date: Thu, 22 Nov 2007 20:24:12 +0200 From: Giorgos Keramidas To: ann kok Message-ID: <20071122182412.GB4258@kobe.laptop> References: <20071122173942.GA3814@kobe.laptop> <985211.7690.qm@web53304.mail.re2.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <985211.7690.qm@web53304.mail.re2.yahoo.com> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-4, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.40, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: freebsd-questions@freebsd.org Subject: Re: can you help about this script 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: Thu, 22 Nov 2007 18:25:03 -0000 On 2007-11-22 10:10, ann kok wrote: > Hi Giorgos > > Thank you > > But my output is from your suggstion > printf "Created: %s\n", system("date +%Y%m%d"); > > 20071122 > Created: 0 > 20071122 > Updated: 0 > > how can I have output as > > Created: 20071122 > Updated: 20071122 You'll have to use the gsub() to strip newlines from the output of "date"... > In additon, > > ls it possible to have loop output also? > > I need to have > > print "File No:", CMA001 > > the second record is CMA002 and then CMA003 for the > 3rd record Sure. One way to do this is to print a formatted version of the special "NR" variable of awk (NR == number of records read so far): $ ( echo foo ; echo bar ) | awk '{ printf "%03d %s\n", NR, $0; }' 001 foo 002 bar $ If you are going to do any amount of *serious* awk programming, I recommend the following book: Dale Dougherty, Arnold Robbins. "Sed & Awk". O'Reilly & Associates. 2nd edition (March 1997) http://www.oreilly.com/catalog/sed2/