Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004
    Posts
    1

    Unanswered: AWK - append system date to fields

    Can anyone please help me figure out how to append the system date to a file. systime() does not work with awk.

    I have something like this already:

    awk -F'|' '

    BEGIN { baanid = " " }

    {
    printf ("%s%s\n"\
    ,$0,"|SPCA|")
    }

    END {
    printf ("%s\n"\
    ,$0)
    }' test.dat > test1.dat


    -------------------------------------

    INPUT FILE:

    100000|MALEGOVD
    100001|TESTING

    CURRENT OUTPUT FILE RESULTS:

    100000|MALEGOVD|SPCA|
    100001|TESTING|SPCA|


    WHAT I WANT:

    100000|MALEGOVD|SPCA|10/07/2004
    100001|TESTING|SPCA|10/07/2004



    I'm really hurting on this one, I am new to AWK and UNIX and have been trying for two frig'n days.

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    Quote Originally Posted by tpb
    Can anyone please help me figure out how to append the system date to a file. systime() does not work with awk.

    I have something like this already:

    awk -F'|' '

    BEGIN { baanid = " " }

    {
    printf ("%s%s\n"\
    ,$0,"|SPCA|")
    }

    END {
    printf ("%s\n"\
    ,$0)
    }' test.dat > test1.dat


    -------------------------------------

    INPUT FILE:

    100000|MALEGOVD
    100001|TESTING

    CURRENT OUTPUT FILE RESULTS:

    100000|MALEGOVD|SPCA|
    100001|TESTING|SPCA|


    WHAT I WANT:

    100000|MALEGOVD|SPCA|10/07/2004
    100001|TESTING|SPCA|10/07/2004



    I'm really hurting on this one, I am new to AWK and UNIX and have been trying for two frig'n days.
    Code:
    nawk '
    
      BEGIN { 
         FS=OFS="|";
         baanid = " "
         cmd=""date +%m/%d/%Y"
         cmd | getline curDate; close(cmd);
      }
    
       {
            printf ("%s%s%s\n"\
                   ,$0, "SPCA", curDate) 
       }
    
    END   {
            printf ("%s\n"\
                   ,$0)                           
          }' test.dat > test1.dat
    
    date +%m/%d/%Y
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  3. #3
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    ooops, sorry:

    change:
    cmd=""date +%m/%d/%Y"
    TO:

    Code:
    cmd="date +%m/%d/%Y"
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •