Using awk or nawk to convert epoch time to date format
Looking for some help and usually when I do a search this site comes up. Hopefully someone can give me a little direction as to how to use one of these two commands to achieve what I'm trying to do.
What am I trying to do?
I need to take the time value in epoch format returned from the system (Solaris) and use A command to convert it to a standard date format of my choosing.
Why not just use date '+%format'?
One main reason is that I need the date 12 hours in the future as a variable for a command that will be executed at a given point in time. If there is a way to do this using just date, I'm all ears. I know with GNU date you can pull epoch with %s, format the time and even add time to the value returned by date using options like "+12 hours" or "-1 day", etc.These options do not work with date on Solaris.
Why not just use Perl or another program language?
Right now there are no options to deploy additional functionality, not even updates to the packages like gawk (which works, btw....GRRRRR!!!!), so we must work within the confines of awk or nawk or whatever else will work. Perl is not installed on the Solaris machines and unfortunately is not an option.
What is needed.
So far I can get the epoch value, but for my variable I need to have the date 12 hours in the future in the following format:
MMDDYYYYTHHMMSS (the 'T' is a delimiter for the program reading the value)
I can achieve this with the current date and time, but not with future date and time. Because I am using Solaris, I cannot use gawk (on this build) and am limited to either awk or nawk as available commands. Again, this is with my limited knowledge. If there is another command that can take epoch time and convert to a date format, please educate me. [FONT=Arial][SIZE=2]
What works, what doesn't.
So far I have tried the following but with syntax errors that are vague at best. This seems like it would be the best solution if I could figure out what Solaris doesn't like about the syntax. I can copy this text and input it directly into a Linux command line and I get what I want, so it's not a matter of typing.
This works in Linux (Fedora 14), but not in Solaris 10.
I'm using nawk this way to get the epoch time.
For the date, I am using this for my start date, but so far I haven't seen a method to calculate the time 12 hours in the future.
So is there any hope? Does anyone have any suggestions that may prove effective?
I have a file named "suspected" with series of line like these :
{'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''}
{'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Hi guys,
I know that this topic has been discuss numerous times, and I have search the net and this forum for it.
However, non able to address the problem I faced so far.
I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Hi,
Is there any easy way to convert date time(stored in shell variable ) to epoch time in solaris box? As +%s is working on linux but not on solaris, also -d option is not working.
Any suggestion please? (6 Replies)
System: HP-UX
Kornshell
Perl is installed, but not POSIX
Hello,
I am calculating a future date/time. To do this I take the system date in epoch format and add to it. I now need to take the new epoch date and convert it to MMDDYYHHmm format.
Any help with this is greatly appreciated. (4 Replies)
Hello
I have log file from solaris system which has date field converted by Java application using System.currentTimeMillis() function, example is 1280943608380 which equivalent to GMT: Wed, 04 Aug 2010 17:40:08 GMT.
Now I need a function in shell script which will convert 1280943608380... (3 Replies)
Can someone help me to write a shell script to convert epoch timestamp into human readable format
1394553600,"test","79799776.0","19073982.728571","77547576.0","18835699.285714"
1394553600,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"... (10 Replies)
Hello Team,
I am stuck in getting the required output in the following case. Please help.
My input file is
aa|08/01/2016
bb|08/15/2016
I wish to convert the file into
aa|epoch time
bb|epoch time
I am using following code: (3 Replies)
Hi,
I have a file where I need to change the date format on the nth field from DD-MM-YYYY to YYYY-MM-DD so I can accurately sort the record by dates
From regex - Use sed or awk to fix date format - Stack Overflow, I found an example using nawk.
Test run as below:
$: cat xyz.txt
A ... (2 Replies)