LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 08-27-2013, 01:16 PM   #1
nab_elf
LQ Newbie
 
Registered: Aug 2013
Posts: 5

Rep: Reputation: Disabled
How to convert a hexadecimal to timestamp via bash script ?


Hello,
please, could you help me to resolve a mesterious problem when i convert time in hexadecimal format to humain format , i mean :

convert for example Ab153d to 00:00:00 with a bash script

Thank's in advance

Last edited by nab_elf; 08-27-2013 at 01:17 PM.
 
Old 08-27-2013, 01:37 PM   #2
duffmckagan
Senior Member
 
Registered: Feb 2005
Distribution: Cent OS 6.4
Posts: 1,163

Rep: Reputation: 49
A quick google search of your requirement came up with the following result. Worth checking out I guess.

http://www.epochconverter.com/epoch/...-timestamp.php
 
Old 08-27-2013, 02:14 PM   #3
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
How's this?

Code:
perl -e '$foo=hex($ARGV[0]); @t=(localtime($foo))[2,1,0]; print $t[0],":",$t[1],":",$t[2],"\n"'  Ab153d
14:28:13

Last edited by smallpond; 08-28-2013 at 12:19 PM. Reason: fix wrong hex conversion
 
Old 08-28-2013, 05:25 AM   #4
nab_elf
LQ Newbie
 
Registered: Aug 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi,
thank's for replying ,

but is there any solution to do the same with bash script instead of perl ?


Thank's
 
Old 08-28-2013, 05:40 AM   #5
nab_elf
LQ Newbie
 
Registered: Aug 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hello

Hello,
please find out in the attachment the resul when i lunch perl command. always the result = 0:0:0
Attached Thumbnails
Click image for larger version

Name:	perl.jpg
Views:	76
Size:	15.2 KB
ID:	13297  
 
Old 08-28-2013, 06:45 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
I'm not entirely sure what your overall goal is, with that in mind.

Assuming that AB153D and 521DD201 are hex representations of linux epoch (seconds from January 1, 1970), have a look at this:
Code:
# hex input is 521dd201:
date --date @$( printf '%d\n' 0x521dd201) '+%Y-%m-%d %T'
2013-08-28 12:33:37

# hex input is Ab153d
date --date @$( printf '%d\n' 0xAb153d) '+%Y-%m-%d %T'
1970-05-10 19:28:13
The printf part converts from hex to decimal, which leaves you with epoch in seconds. This epoch can be given to the date command (--date @no_of_seconds), the last part ('+%Y-%m-%d %T') specifies the wanted output.

See the date manual page for details.
 
Old 08-28-2013, 06:45 AM   #7
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Code:
printf "%d\n" 0x521DD201

date --date="@$(printf "%d\n" 0x521DD201)"

date "+%Y-%m-%d %H:%M:%S ( %s )" --date="@$(printf "%d\n" 0x521DD201)"

too slow

Last edited by Firerat; 08-28-2013 at 06:46 AM.
 
Old 08-28-2013, 06:51 AM   #8
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
and if you wanted to go the other way..

Code:
printf '0x%x\n' $(date +%s)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Find out timestamp line and delete if it is older than particular/specific days using bash script nitya Linux - Newbie 10 09-26-2014 01:30 PM
[SOLVED] log bash script output to file with timestamp daisychick Programming 11 05-08-2013 01:50 AM
convert string to hexadecimal kpachopoulos Programming 3 12-11-2007 06:23 AM
Adding timestamp to a BASH script thefox Linux - Software 1 11-10-2007 09:29 PM
function in shell to convert hexadecimal into ascii suchi_s Linux - Software 1 04-01-2005 02:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 11:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration