AIX : Need to convert UNIX Timestamp to normal timestamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AIX : Need to convert UNIX Timestamp to normal timestamp
# 1  
Old 10-29-2015
AIX : Need to convert UNIX Timestamp to normal timestamp

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

Code:
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 :

Code:
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
# 2  
Old 10-29-2015
Hello Rahul,

Could you please try following and let us know if this helps.
Code:
awk '/EFFECTIVE_TIME/{ printf "%s -- %s\n", strftime("%c",$2), $0 }'  Input_file

Output will be as follows.
Code:
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.
Code:
awk '/EFFECTIVE_TIME/{ printf "%s\n", strftime("%c",$2);next} 1'  Input_file

Output will be as follows.
Code:
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
# 3  
Old 10-29-2015
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
# 4  
Old 10-29-2015
With a recent shell, try
Code:
printf "%(%F %T)T\n" 1279635438
2010-07-20 16:17:18

# 5  
Old 10-29-2015
Hello RudiC,

The shell seems old. The project is using AIX 5.3. Although I will test this command ASAP.

Thanks
Rahul
# 6  
Old 10-29-2015
If it doesn't work with ksh on AIX, try using ksh93.
# 7  
Old 10-31-2015
Hi.
Code:
perl -le ' print scalar localtime(shift)' 1279635438

producing:
Code:
Tue Jul 20 16:17:18 2010

on a system like:
Code:
aix 7.1.0.0
perl 5.10.1

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies

2. Shell Programming and Scripting

Convert date in dd mm yyyy format to UNIX timestamp

Hello All, I have a date in DD/MM/YYYY format. I am trying to convert this into unix timestamp. I have tried following: date -d $mydate +%s where mydate = 23/12/2016 00:00:00 I am getting following error: date: extra operand `+%s' Try `date --help' for more information. ... (1 Reply)
Discussion started by: angshuman
1 Replies

3. Shell Programming and Scripting

Convert UNIX timestamp to readable format in the file

Hello I have a file : file1.txt with the below contents : 237176 test1 test2 1442149024 237138 test3 test4 1442121300 237171 test5 test7 1442112823 237145 test9 test10 1442109600 In the above file fourth field represents the timestamp in Unix format. I found a command which converts... (6 Replies)
Discussion started by: rahul2662
6 Replies

4. Shell Programming and Scripting

To check timestamp in logfile and display lines upto 3 hours before current timestamp

Hi Friends, I have the following logfile. Currently time in india is 07/31/2014 12:33:34 and i have the following content in logfile. I want to display only those entries which contain string 'Exception' within last 3 hours. In this case, it would be the last line only I can get the... (12 Replies)
Discussion started by: srkmish
12 Replies

5. UNIX for Dummies Questions & Answers

How to convert R$Timestamp in Sql*Plus within a UNIX Shell Script?

I need to compare a R$Timestamp field sql within a Unix Shell Script. In straight SQL the following code works fine: Table Name: LL_UNIT_TRANSACTION UT Field: R$Timestamp Where TRUNC(UT.R$Timestamp) >= TRUNC(SYSDATE -7) the following returns no data within the Unix Shell Script... (2 Replies)
Discussion started by: Dapconsult
2 Replies

6. AIX

convert a specific date to a unix timestamp

hello, i have an AIX5.3 machine and i am writing a script to display some processes. inside the script i want to get the time that the process starts and convert it to a unix timestamp. is there a command that i can use to do that? i search the web but all i found is long scripts and it does... (4 Replies)
Discussion started by: omonoiatis9
4 Replies

7. AIX

Convert unix timestamp to year month day format ?

Hello, How do I convert unix timestamp value to 'normal' date format - to get year month and day values ? Looks like it's easy to do using GNU date (linux systems). But how do I do tthis on AIX ? I don't want to write C program, any ways to do that using unix shells ? thanks (1 Reply)
Discussion started by: vilius
1 Replies

8. Shell Programming and Scripting

To convert a date(in string format) to unix timestamp

Hi All, I have a string like below. "Mar 31 2009" . I want to convert this to unix time . Also please let me know how to find the unix time for the above string minus one day. For Eg. if i have string "Mar 31 2009" i want to find the unix time stamp of "Mar 30 2009". Thanks in advance,... (11 Replies)
Discussion started by: girish.raos
11 Replies

9. Shell Programming and Scripting

Convert Unix Timestame to real timestamp

Hello, Did anyone know how to use script (e.g. perl) to conver Unix Timestame to real timestame in GMT+8 ? 1245900787 file:/tmp/a/Test/.txt.swp has created 1245900988 file:/tmp/a/Test/.txt.swp has changed Thu, 25 Jun 2009 11:33:07 GMT+8 file:/tmp/a/Test/.txt.swp has created Thu, 25 Jun... (4 Replies)
Discussion started by: happyday
4 Replies

10. UNIX for Advanced & Expert Users

AIX/awk date to unix timestamp

Hello, I am inside a awk script on AIX, I am feeding to awk ls -luNR i need to convert ls -u time format "month day h:m/yr" to Unix epoch time, POSIX time, or aka unix timestamp I do not have strftime funk in my awk, and i have to do this fast meaning that I cannot do a system call in the... (1 Reply)
Discussion started by: nullwhat
1 Replies
Login or Register to Ask a Question