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.

you'll likely find an answer within the FAQ area. There is a great article:

http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html

which has all sorts of goodies in... HTH

Thank you for the link, Tytalus. However, just like Bono Vox, I still haven't found what I am looking for :slight_smile: . 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!

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 ?

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.

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.