From owner-freebsd-questions@FreeBSD.ORG Thu Nov 22 18:10:23 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 19CCA16A41B for ; Thu, 22 Nov 2007 18:10:23 +0000 (UTC) (envelope-from annkok2001@yahoo.com) Received: from web53304.mail.re2.yahoo.com (web53304.mail.re2.yahoo.com [206.190.49.94]) by mx1.freebsd.org (Postfix) with SMTP id C7C5813C4E5 for ; Thu, 22 Nov 2007 18:10:22 +0000 (UTC) (envelope-from annkok2001@yahoo.com) Received: (qmail 8231 invoked by uid 60001); 22 Nov 2007 18:10:11 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=lU40vCVPmP0aYZBaeRTDj83n4Ukj0cmDiq4FYcv+qvzB/Qmz8wSaMC1EYa7mGSODfXRCEB39OdsWr7JU+0OKXVfF3y/AsjaOIZzet2hS1OFcbuAsfHjFvh5dxZK6eIBvnDNZ86wkPdANfE9G5TWbYj/xrXXj9mCOyuaU8I5tvqg=; X-YMail-OSG: b5Dky1gVM1l6WlONf1yskaT.8KnmQV5NACOeGP3dHGcERsxpoCF7zDakPmNvay8Ez2xSFdl_5wdgnmSJeDwgx8AYcu5Le._qtQe7le_nMAUZEzOMu.m26wX11A-- Received: from [66.49.254.13] by web53304.mail.re2.yahoo.com via HTTP; Thu, 22 Nov 2007 10:10:10 PST Date: Thu, 22 Nov 2007 10:10:10 -0800 (PST) From: ann kok To: Giorgos Keramidas In-Reply-To: <20071122173942.GA3814@kobe.laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <985211.7690.qm@web53304.mail.re2.yahoo.com> 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:10:23 -0000 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 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 awk -f program.awk record.txt Thank you again --- Giorgos Keramidas wrote: > On 2007-11-21 12:26, ann kok > wrote: > > Hi all > > how command "date, hostname" run in awk program? > > > > awk -F program.awk file.txt > > You don't use backticks... These are a feature of > the shell, and > running a script through progname.awk is no longer a > shell session. > > Try system("date") in your awk(1) script: > > > program.awk > > > > BEGIN { RS = "\n" ; FS = "|" } > > > > { > > print "Name:", $9 > > print "Created: `date`" > > print "from: `hostname`" > > print "" > > } > > > BEGIN { > RS ="\n"; > FS = "|"; > } > > { > printf "Name: %s\n", $9; > printf "Created: %s\n", > system("date"); > printf "From: %s\n", > system("hostname"); > } > > Running system("hostname") once for each file may be > horribly > inefficient, though. If I were you, I'd write this > as a *shell* script, > which runs "hostname" once, stashes the result away > in a variable, and > reuses it all the time. > > Running "date" may be a bit less efficient than > something like > gettimeofday(). Perl has a gettimeofday() function > in the Time::HiRes > module, so it may be worth investigating if that may > speed things up a > bit more. > > A completely untested first try to do something like > this is ... > > #!/usr/bin/perl -w > > use strict; > > use POSIX qw(strftime); > use Time::HiRes qw(gettimeofday); > > my $hostname = `hostname`; > my $line; > while (defined($line = )) { > chomp $line; > my @fields = split /|/, $line; > if ($#fields >= 0) { > my ($seconds, $microseconds) > = gettimeofday(); > printf "Name: %s\n", > $fields[8]; > printf "Created: %s\n", > strftime("%Y-%m-%d > %H:%M:%S", gmtime($seconds)); > printf "From: %s\n", > $hostname; > } > } > > --- Giorgos Keramidas wrote: > On 2007-11-21 12:26, ann kok > wrote: > > Hi all > > how command "date, hostname" run in awk program? > > > > awk -F program.awk file.txt > > You don't use backticks... These are a feature of > the shell, and > running a script through progname.awk is no longer a > shell session. > > Try system("date") in your awk(1) script: > > > program.awk > > > > BEGIN { RS = "\n" ; FS = "|" } > > > > { > > print "Name:", $9 > > print "Created: `date`" > > print "from: `hostname`" > > print "" > > } > > > BEGIN { > RS ="\n"; > FS = "|"; > } > > { > printf "Name: %s\n", $9; > printf "Created: %s\n", > system("date"); > printf "From: %s\n", > system("hostname"); > } > > Running system("hostname") once for each file may be > horribly > inefficient, though. If I were you, I'd write this > as a *shell* script, > which runs "hostname" once, stashes the result away > in a variable, and > reuses it all the time. > > Running "date" may be a bit less efficient than > something like > gettimeofday(). Perl has a gettimeofday() function > in the Time::HiRes > module, so it may be worth investigating if that may > speed things up a > bit more. > > A completely untested first try to do something like > this is ... > > #!/usr/bin/perl -w > > use strict; > > use POSIX qw(strftime); > use Time::HiRes qw(gettimeofday); > > my $hostname = `hostname`; > my $line; > while (defined($line = )) { > chomp $line; > my @fields = split /|/, $line; > if ($#fields >= 0) { > my ($seconds, $microseconds) > = gettimeofday(); > printf "Name: %s\n", > $fields[8]; > printf "Created: %s\n", > strftime("%Y-%m-%d > %H:%M:%S", gmtime($seconds)); > printf "From: %s\n", > $hostname; > } > } > > ____________________________________________________________________________________ Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how. http://overview.mail.yahoo.com/