Hello ,
I am working on AIX. I have to convert Unix timestamp to normal timestamp. Below is the file. The Unix timestamp will always be preceded by
EFFECTIVE_TIME as first field as shown and there could be multiple EFFECTIVE_TIME in the file : 3.txt
Contents of /usr/openv/netbackup/db/class/PRDEWQ_OS/info :
\n
ACTIVE 0
EFFECTIVE_TIME 1279635438
\n
Contents of /usr/openv/netbackup/db/class/PRDEWQ_OS/schedule/Full/days :
\n
0 0 39600
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
\n
Contents of /usr/openv/netbackup/db/class/PRDEWQ_OS/schedule/Full/info :
\n
\n
Contents of /usr/openv/netbackup/db/class/PRDEWQ_OS/schedule/Incremental/days :
\n
0 0 0
1 0 25200
2 0 25200
3 0 25200
4 0 25200
5 0 25200
6 0 25200
\n
Contents of /usr/openv/netbackup/db/class/PRDEWQ_OS/schedule/Incremental/info :
\n
\n
I ran the following but it failed :
awk '/EFFECTIVE_TIME/ { printf "%s %s\n", $1,$(perl -le 'print scalar localtime(shift)' $2); next} 1' 3.txt
-bash: syntax error near unexpected token `('
Could someone please help.
Thanks
Rahul
Hello Rahul,
Could you please try following and let us know if this helps.
awk '/EFFECTIVE_TIME/{ printf "%s -- %s\n", strftime("%c",$2), $0 }' Input_file
Output will be as follows.
Tue Jul 20 10:17:18 2010 -- EFFECTIVE_TIME 1279635438
EDIT: For getting exact time with all the lines in Input_file, you could try following then.
awk '/EFFECTIVE_TIME/{ printf "%s\n", strftime("%c",$2);next} 1' Input_file
Output will be as follows.
Contents of /usr/openv/netbackup/db/class/PRDEWQ_OS/info :
\n
ACTIVE 0
Tue Jul 20 10:17:18 2010
\n
Contents of /usr/openv/netbackup/db/class/PRDEWQ_OS/schedule/Full/days :
\n
0 0 39600
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
\n
Contents of /usr/openv/netbackup/db/class/PRDEWQ_OS/schedule/Full/info :
\n
\n
Contents of /usr/openv/netbackup/db/class/PRDEWQ_OS/schedule/Incremental/days :
\n
0 0 0
1 0 25200
2 0 25200
3 0 25200
4 0 25200
5 0 25200
6 0 25200
\n
Contents of /usr/openv/netbackup/db/class/PRDEWQ_OS/schedule/Incremental/info :
\n
\n
Thanks,
R. Singh
Hello Ravinder,
The strftime function doesnt works in AIX Server. I got the following error :
awk: 0602-553 Function strftime is not defined.
Thanks
Rahul
RudiC
October 29, 2015, 10:20am
4
With a recent shell, try
printf "%(%F %T)T\n" 1279635438
2010-07-20 16:17:18
Hello RudiC,
The shell seems old. The project is using AIX 5.3. Although I will test this command ASAP.
Thanks
Rahul
If it doesn't work with ksh
on AIX, try using ksh93
.
drl
October 31, 2015, 11:48am
7
Hi.
perl -le ' print scalar localtime(shift)' 1279635438
producing:
Tue Jul 20 16:17:18 2010
on a system like:
aix 7.1.0.0
perl 5.10.1
Best wishes ... cheers, drl