If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > AWK - append system date to fields

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-07-04, 15:23
tpb tpb is offline
Registered User
 
Join Date: Jul 2004
Posts: 1
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.
Reply With Quote
  #2 (permalink)  
Old 10-07-04, 16:17
vgersh99 vgersh99 is offline
Registered User
 
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> |
+-----------------------+
Reply With Quote
  #3 (permalink)  
Old 10-07-04, 16:19
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
ooops, sorry:

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

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On