convert unix date to readable format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting convert unix date to readable format
# 1  
Old 10-14-2008
convert unix date to readable format

Dear Experts,

I need your help to convert a unix date and time format number in to readable format like dd/mm/yyyy .
I have a text file of more than 10,000 records and it is like

NAME DATE1 COUNTRY DATE2
ABD 1223580395699 USA 1223580395699
ABD 1223580395699 USA 1223580395699
ABD 1223580395699 USA 1223580395699
ABD 1223580395699 USA 1223580395699
ABD 1223580394340 USA 1223580387665

I need a unix shell script which will read the records from first line and till end of the file and should convert the unix date to readable format like "ddmmyy".
output should be like this

NAME DATE1 COUNTRY DATE2
ABD 14102008 USA 14102008
NAME 14102008 COUNTRY 14102008

Please tel me how i can achieve this by a unix shell script which can convert any unix datetime like 1223580395699 to a readable format like ddmmyyyy.
Thanks
# 2  
Old 10-14-2008

Those are not Unix timestamps; the numbers exceed 32 bits.

1223580395699 is 40743-09-21. (Note: I always use the ISO standard date format.)

This code divides the number by 1,000 to get a valid date, and requires GNU awk:

Code:
gawk 'NR == 1 { print; next }
{
  $2 = strftime( "%Y-%m-%d", $2 / 1000 )
  $4 = strftime( "%Y-%m-%d", $4 / 1000 )
  print
}' "$FILE"

# 3  
Old 10-15-2008
Hi,

Thnaks for your support but i have tried and it was not working so can you please tell me some other way of doing it.
Is it possible to do this with for loop or any other shell script.
Thanks
# 4  
Old 10-15-2008
Quote:
Originally Posted by shary
Thnaks for your support but i have tried and it was not working so can you please tell me some other way of doing it.

What does "not working" mean? What did happen?

If the output was incorrect, please post it.

If you received error messages, please post them.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

3. Shell Programming and Scripting

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 1394553600,"test","79799776.0","19073982.728571","77547576.0","18835699.285714" 1394553600,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"... (10 Replies)
Discussion started by: Moon1234
10 Replies

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

5. Shell Programming and Scripting

Need a unix script to convert date into Julian format in a text file

The 6th & 7th column of the text files represents date & time. I need this to be converted in julian format using command "date +%s -d <date>". I know the command, but dont know how to use it on the script 0 dbclstr-b IXT_Web Memphis_Prod_SQL_Full Memphis-Prod-SQL-Full-Application-Backup... (4 Replies)
Discussion started by: ajiwww
4 Replies

6. Shell Programming and Scripting

Convert date to Unix format

Dear Expert How to convert date in format of YYYY-MM-DD HH:MM:SS to unix format using a script or command if avaliable Example "2011-05-15 18:00:00" is converted to 1330970400 I tried to use option d in date command but no use, Im using solaris 10 Thanks a lot (12 Replies)
Discussion started by: yahyaaa
12 Replies

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

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 date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

10. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies
Login or Register to Ask a Question