Hello
I need to split big xml file into multiple files based on xml declaration. for that i have written one awk 1 liner as below
awk '/<?xml\ version/{i++}{print > "outfile."i}' test123.xml
this is producing the desired out put. but i want the the currenttimestamp with milliseconds in the file name rather than outfile as filename.
ex: outfile=currenttimestamp with milliseconds (YYYYMMDDHHMISSSS) format.
ex:2012080819371613.1
Please help me
Thanks
Dsdev123
agama
2
If your local date command supports the rfc 3339 option, then this brute force way works:
awk '
function ts( c ) # timestamp with nano sec
{
c = "date --rfc-3339=ns | sed -E \"s/(..)-(..)-/\1\2/;s/ //; s/-.*//;s/://g\"";
c | getline timestamp;
close( c );
}
/<?xml\ version/{ ts(); }{ print >"outfile." timestamp; } ' in-file
I tried this but its not working . iam using AIX 6.1.
Thanks again
agama
4
Assuming that you don't have GNU date available then. You could write a small bit of C and invoke the binary:
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int main( )
{
struct tm ltime;
struct timeval tv;
time_t now;
now = time( NULL );
localtime_r( &now, <ime );
gettimeofday( &tv, NULL );
printf( "%4d%02d%02d%02d%02d%02d.%d\n", ltime.tm_year + 1900, ltime.tm_mon + 1, ltime.tm_mday, ltime.tm_hour, ltime.tm_min, ltime.tm_sec, tv.tv_usec );
return 0;
}
If programme is saved as datens.c
then this command should build datens
binary:
cc -o datens datens.c
This of course assumes your libc includes gettimeofday(). I don't have access to an AIX box, so I'm unsure what other options you might have.