Convert epoch time stamp into human readable format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert epoch time stamp into human readable format
# 1  
Old 03-12-2014
Convert epoch time stamp into human readable format

Can someone help me to write a shell script to convert epoch timestamp into human readable format

Code:
1394553600,"test","79799776.0","19073982.728571","77547576.0","18835699.285714"
1394553600,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"
1394553600,"test2","34.233830","34.132758","10086.9180","9933.306071"
1394553600,"test3","10617.3400","8794.801030","1072.77640","783.440867"
1394553600,"test4","9900.946","9852.964286","11260.573","11231.444714"

the first field denotes epoch time stamp

Last edited by bartus11; 03-12-2014 at 03:23 PM.. Reason: Please use [code][/code] tags.
# 2  
Old 03-12-2014
What would be the desired output for this sample data?
# 3  
Old 03-12-2014
Assuming your first column is the epoch time
you can do this (from man date)

date --date='@2147483647'
# 4  
Old 03-12-2014
nput
Code:
"_time",mynode,"Data1","Data2","Data3","Data4"
1394553600,"test","79799776.0","19073982.728571","77547576.0","18835699.285714"
1394553600,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"
1394553600,"test2","34.233830","34.132758","10086.9180","9933.306071"
1394553600,"test3","10617.3400","8794.801030","1072.77640","783.440867"
1394553600,"test4","9900.946","9852.964286","11260.573","11231.444714"

Expected Output
Code:
"_time",mynode,"Data1","Data2","Data3","Data4"
3/11/2014 16:00:00"test","79799776.0","19073982.728571","77547576.0","18835699.285714"
3/11/2014 16:00:00,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"
3/11/2014 16:00:00,"test2","34.233830","34.132758","10086.9180","9933.306071"
3/11/2014 16:00:00,"test3","10617.3400","8794.801030","1072.77640","783.440867"
3/11/2014 16:00:00,"test4","9900.946","9852.964286","11260.573","11231.444714"

if possible can i get the time stamp in EST time zone

---------- Post updated at 01:36 PM ---------- Previous update was at 01:36 PM ----------

Quote:
Originally Posted by bartus11
What would be the desired output for this sample data?
Input
Code:
"_time",mynode,"Data1","Data2","Data3","Data4"
1394553600,"test","79799776.0","19073982.728571","77547576.0","18835699.285714"
1394553600,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"
1394553600,"test2","34.233830","34.132758","10086.9180","9933.306071"
1394553600,"test3","10617.3400","8794.801030","1072.77640","783.440867"
1394553600,"test4","9900.946","9852.964286","11260.573","11231.444714"

Expected Output
Code:
"_time",mynode,"Data1","Data2","Data3","Data4"
3/11/2014 16:00:00"test","79799776.0","19073982.728571","77547576.0","18835699.285714"
3/11/2014 16:00:00,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"
3/11/2014 16:00:00,"test2","34.233830","34.132758","10086.9180","9933.306071"
3/11/2014 16:00:00,"test3","10617.3400","8794.801030","1072.77640","783.440867"
3/11/2014 16:00:00,"test4","9900.946","9852.964286","11260.573","11231.444714"

if possible can i get the time stamp in EST time zone

Last edited by Don Cragun; 03-12-2014 at 04:08 PM.. Reason: Add CODE tags.
# 5  
Old 03-12-2014
try this

Code:
while read line;do
  ts=`echo "$line"|cut -f1
  rest=`echo "$line"|cut -f2-
  d=`date --date="@${ts}"
  echo "$d,$rest"
done < inputfile > output file


Last edited by Don Cragun; 03-12-2014 at 03:55 PM.. Reason: Fix CODE tags.
# 6  
Old 03-12-2014
Quote:
Originally Posted by linuxpenguin
try this

while read line;do
ts=`echo "$line"|cut -f1
rest=`echo "$line"|cut -f2-
d=`date --date="@${ts}"
echo "$d,$rest"
done < inputfile > outputfile
it's not working... Smilie
# 7  
Old 03-12-2014
do you see errors, or the output file is not what you want?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting a random epoch time into a readable format

I am trying to create a script that will take epoch (input from command line) and convert it into a readable format in bash/shell ---------- Post updated at 08:03 PM ---------- Previous update was at 07:59 PM ---------- #!bin/bash read -p "Please enter a number to represent epoch time:"... (9 Replies)
Discussion started by: sprocket
9 Replies

2. Shell Programming and Scripting

Multiple records need to convert UNIXtime to human readable datatime and all output in one format

Hello Experts, Below is the record i have: sample data attached I want this record of each row to be in single line and there are multiple rowise unixtime mentioned e.g 11996327 , This needs to be converted to Human readdable data and time from multiple rows Can you help me , it will be... (10 Replies)
Discussion started by: manishK
10 Replies

3. UNIX for Dummies Questions & Answers

Display Directories with their sizes in human readable format

Hi, I want to list all the directories present in a particular location and want to display their sizes as well. I know "ls -lh" but it doesn't show the size of the complete directory. So i want something like dir1 266 MB dir2 2 KB dir3 22 MB ... ... file1 10 Kb ..... Thanks Sarbjit (4 Replies)
Discussion started by: sarbjit
4 Replies

4. Shell Programming and Scripting

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... (5 Replies)
Discussion started by: minigts
5 Replies

5. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

6. Shell Programming and Scripting

Convert epoch to human readable date & time format

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)
Discussion started by: Yaminib
3 Replies

7. UNIX for Dummies Questions & Answers

How to make user's qutoa in human readable format?

$ quota Disk quotas for user cqlouis (uid 1254): Filesystem blocks quota limit grace files quota limit grace /dev/sdb1 64 300000 320000 8 0 0 $ I want to make the output of command quota in human readable format? How to? As we... (2 Replies)
Discussion started by: cqlouis
2 Replies

8. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

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)
Discussion started by: rk4k
3 Replies

9. Shell Programming and Scripting

script to convert epoch into human-readable

This is what I have to start out with more file 1208217600 1208131200 1193806800 I want to convert the epoch column into a human-readable format. My file has hundreds of these epoch times that I want to loop through and convert. (The epoch time is really the last column of the line) ... (3 Replies)
Discussion started by: snoman1
3 Replies

10. Shell Programming and Scripting

how to convert epoch time to readible format?

Hi, I would like to convert epoch time from the logs to readible fromat. How do I do it within shell? Thanks! (11 Replies)
Discussion started by: cin2000
11 Replies
Login or Register to Ask a Question