Using Date command 
Author Message
 Using Date command

How do I print the current date to an output file?  I tried:  "date" |
getfile todaysdate , and then printing the variable todaysdate, but it
seems that the getfile is stuck in a loop.  I tried: close("date") but
that did not help.  I put the following in a short program:

BEGIN {

  "date" | getline todaysdate
  printf("\n %s \n", todaysdate)
  close("date")

Quote:
}

END

The printf is not executed until a CR is pressed on the keyboard.  Then
the todaysdate string is printed on the standard output, but the program
does not terminate unless a Ctrl-c is pressed.  Is this the only means
of acquiring the current date?

Thanks,

Jeff Safire



Wed, 10 Jul 2002 03:00:00 GMT  
 Using Date command

Quote:

> How do I print the current date to an output file?

$ /bin/date >outputfile

Quote:
> I tried: "date" | getfile [sic] todaysdate , and then printing
> the variable todaysdate, but it seems that the getfile [sic] is
> stuck in a loop.

What loop could it get stuck in? There's only one possibility,
and it's not one you can see expressed in your script.

Quote:
> I tried: close("date") but that did not help. I put the following
> in a short program:

> BEGIN {
>   "date" | getline todaysdate
>   printf("\n %s \n", todaysdate)
>   close("date")
> }
> END

> The printf is not executed until a CR is pressed on the keyboard. Then
> the todaysdate string is printed on the standard output, but the program
> does not terminate unless a Ctrl-c is pressed. Is this the only means
> of acquiring the current date?

You're obviously using an older version of awk that requires an
explicit exit statement at the end of a BEGIN block to curb awk's
natural hunger for input. And perhaps because I/O is buffered,
you're not seeing the date printed until after awk reads the first
line of input, which is the newline produced by your pinky hitting
the Enter key.

Try this:

#!/bin/awk -f
BEGIN {
    "/bin/date" | getline today
    print today
    exit  # Stop. Don't read input.

Quote:
}

And lose the dangling END.

--
Jim Monty

Tempe, Arizona USA



Wed, 10 Jul 2002 03:00:00 GMT  
 Using Date command


   >How do I print the current date to an output file?  I tried:
   >"date" | getfile todaysdate , and then printing the variable
   >todaysdate, but it seems that the getfile is stuck in a loop.  I
   >tried: close("date") but that did not help.  I put the following in
   >a short program:
   >BEGIN {
   >"date" | getline todaysdate
   >printf("\n %s \n", todaysdate)
   >close("date")
   >}
   >END
   >The printf is not executed until a CR is pressed on the keyboard.
   >Then the todaysdate string is printed on the standard output, but
   >the program does not terminate unless a Ctrl-c is pressed.  Is this
   >the only means of acquiring the current date?

According to your headers, you are using Windows NT.  If that is the system
on which you run your awk script, there is an option for "date" to make it
not ask for a new date.  I think it's "date /d", to be sure type "date /?".
On a DOS or Win9x system you would use "echo.|date" | getline todaysdate

Net-Tamer V 1.08X - Test Drive



Thu, 11 Jul 2002 03:00:00 GMT  
 Using Date command


Quote:
>How do I print the current date to an output file?  I tried:  "date" |
>getfile todaysdate , and then printing the variable todaysdate, but it
>seems that the getfile is stuck in a loop.  I tried: close("date") but
>that did not help.  I put the following in a short program:

>BEGIN {

>  "date" | getline todaysdate
>  printf("\n %s \n", todaysdate)
>  close("date")
>}
>END

>The printf is not executed until a CR is pressed on the keyboard.  Then
>the todaysdate string is printed on the standard output, but the program
>does not terminate unless a Ctrl-c is pressed.  Is this the only means

 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Quote:
>of acquiring the current date?

>Thanks,

Jeff --

This sounds like DOS.  

If you're using gawk then try

printf ( "\n%s\n", strftime ())

If you want a different format for the strftime() output,
see man strftime().

Try to avoid system () and getline |foo commands --
they are not portable.

HTH.

-- kjh ( if you're not using gawk, why not ? ;-)
--
------------------------------------------------------------

1111 Seacoast Dr.  Unit 41   |  home:   (619) 423-4451     |
Imperial Beach, CA   91932   |                             |



Sat, 13 Jul 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Invalid dates - 215 using Btrieve/Clipper DATE format

2. Difficulties with dates / using the date.rb module

3. Find files with command line date

4. Expect date command for Newbie!

5. Date limitation of clock command

6. setting the output of the unix date command

7. A clock command that handle international dates...

8. how to do dos date and time commands

9. Using + and - to change date field

10. using clarion dates in other applications

11. transforming dates when using other languages

12. Advantage of Using Date vs Long?

 

 
Powered by phpBB® Forum Software