Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Nov 2007 20:24:12 +0200
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        ann kok <annkok2001@yahoo.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: can you help about this script
Message-ID:  <20071122182412.GB4258@kobe.laptop>
In-Reply-To: <985211.7690.qm@web53304.mail.re2.yahoo.com>
References:  <20071122173942.GA3814@kobe.laptop> <985211.7690.qm@web53304.mail.re2.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2007-11-22 10:10, ann kok <annkok2001@yahoo.com> 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/




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071122182412.GB4258>