Change specific (not current) date to timestamp


 
Thread Tools Search this Thread
Operating Systems AIX Change specific (not current) date to timestamp
# 1  
Old 03-30-2011
Change specific (not current) date to timestamp

Hello to all.

I work at AIX system without perl installed and I am restricted user, so I am limited to bash. In script that I am writing, I have to read line from file and transform date that I found inside to Unix timestamp. Line in file look something like this:

Tue Mar 29 06:59:00 GMT+02:00 2011

I wrote script in bash at home doing this transformation with following lines:

...
datum_temp=`echo $DATE_TIME_LINE | awk '{ print $1 " " $2 " " $3 " " $5 " "}' `
FIRST_TIMESTAMP=`date +%s -d"$datum_temp"`
...

However, when I try to do this in AIX it failed, because AIX doesn't have -d . I searched Internet and found solutions with perl, some C templates etc. I really want to keep it simple (if possible), so can you please point me to right direction? Thanks in advance.
# 2  
Old 03-30-2011
you'll likely find an answer within the FAQ area. There is a great article:

https://www.unix.com/answers-frequent...rithmetic.html

which has all sorts of goodies in... HTH
# 3  
Old 03-31-2011
Thank you for the link, Tytalus. However, just like Bono Vox, I still haven't found what I am looking for Smilie . I did one ugly workaround (using: find -mmin -90... something like that), that relies on file timestamp. So... question stays opened, but it's not urgent any more. Thanks for help!
# 4  
Old 03-31-2011
It is not quite clear if you want to just see the timestamp of a file and change it or use it in a string.

are you trying to change the last modified date/time of the file ?
or
are you just trying to read the date/time stamp of the file and store it in a string ?
# 5  
Old 03-31-2011
Here is the problem:

I have file. Lines in file looks something like this (I remove extra strings):

Mar 29 06:59:00 2011 (this is not current time!)
Mar 29 09:59:00 2011
Mar 29 19:59:00 2011
etc...

What I need to do is to transform date and time from line to unix timestamp and save it as a string in variable. In bash, this is not hard, because date command have -d option that does exactly this:
...
FIRST_TIMESTAMP=`date +%s -d"$first_line"`
SECOND_TIMESTAMP=`date +%s -d"$second_line"`
...

So, this is what I need and it worked without problem. But, in AIX, date command doesn't have -d option. If I try to execute: "date +%s" that will work as expected, but only for current date and time. I couldn't find a way to tell him: I want this specific time to transform to timestamp. I hope that I was clearer now.

By the way, I read linked post from first answer and I couldn't find what I needed (maybe I missed it in reading, but I doubt). I also need bash to do this (no perl or asking Informix database, as one of the posters suggest in his solution). Thanks in advance!


P.S. I used awk in first post because line look slightly different, so I have to remove some of the columns.
# 6  
Old 03-31-2011
Well, I saw your awk solution and I am not sure if there is anything wrong with that. The command 'date' is a fickle b*+c4 (pardon the language) and doesn't work portably between any two flavor of UNIX for that matter. For instance %s is not a valid format on HPUX if this tells you something.

For date calcualtions, there is a script called caljd(.sh or .pl) written by A. Clay Stephenson (of HP ITRC Forums fame) which does a lot of things regarding date manipulation. It is mirrored somewhere under Merijn's HP-UX software for ITRC members. It might worth taking a look.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to change existing date to current date in a filename?

Suppose i have a list of files in a directory as mentioned below 1. Shankar_04152019_ny.txt 2. Gopi_shan_03122019_mi.txt 3. Siva_mourya_02242019_nd.txt .. . . . . 1000 . Jiva_surya_02282019_nd.txt query : At one shot i want to modify the above all filenames present in one path with... (4 Replies)
Discussion started by: Shankar455
4 Replies

2. 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

3. 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

4. UNIX and Linux Applications

Reflection Macro: Use Current Date Information in specific field of report

Hi Everyone, New to the forum, and have my first question. I have the following Macro currently being used within Telnet to run a report for the date being entered. However, now I need the Macro to input the day after today to the the day after today. Example: If today is May 9, 2012 - the... (0 Replies)
Discussion started by: CipherEffect
0 Replies

5. 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

6. Shell Programming and Scripting

Check if a date field has date or timestamp or date&timestamp

Hi, In a field, I should receive the date with time stamp in a particular field. But sometimes the vendor sends just the date or the timestamp or correctl the date&timestamp. I have to figure out the the data is a date or time stamp or date&timestamp. If it is date then append "<space>00:00:00"... (1 Reply)
Discussion started by: machomaddy
1 Replies

7. UNIX for Advanced & Expert Users

In ksh find out the timestamp of current date?

Normally we can use %s to find out the time in second since 1970. But in my ksh, this format option is not available. Example- date +%s 1268103151 above script command won't work in ksh. Can you guys provide its equivalent ? (3 Replies)
Discussion started by: boy18nj
3 Replies

8. Shell Programming and Scripting

Compare file timestamp with current date. Diff must be 1 hour.

Hello, I've created the script below to compare the content of two files with a delay of an hour. After an hour, the lines that exist in both files, will be printed and executed. The script now uses a counter to countdown 50 minutes. But what I would prefer is to check the file timestamp of... (3 Replies)
Discussion started by: taipan
3 Replies

9. AIX

how to grep and compare timestamp in a file with the current date

I want to read a log file from a particular location.In the log file each line starts with timestamp.I need to compare the timestamp in the logfile with the current date.If the timpestamp in the log file is less than 4 hours then i need to read the file from that location.Below is the file... (1 Reply)
Discussion started by: achu
1 Replies

10. AIX

how to grep and compare timestamp in a file with the current date

I want to read a log file from a particular location.In the logfile , lines contains timestamp.I need to compare the timestamp in the logfile with the current date.If the timpestamp in the log file is less than 4 hours then i need to read the file from that location.Below is the file format.Please... (1 Reply)
Discussion started by: achu
1 Replies
Login or Register to Ask a Question