reformat ugly time format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reformat ugly time format
# 1  
Old 10-11-2011
reformat ugly time format

hi all,

i am working in bash and grep a timestamp from a file. now i need to do some calculation on it. unfortunately it is in an ugly time format:

Tue Oct 11 10:11:39 2011

does anyone of you know how to reformat that ugly string so that i get the seconds from the beginning of this decade

something similiar to the result of the bash command "date +%s" would be great.
# 2  
Old 10-11-2011
work with this:
Code:
date -d "Tue Oct 11 09:53:25 2011" +%s
#  or 
string="Tue Oct 11 09:53:25 2011"
secs=$( date -d "$string" +%s  )
echo $secs

This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 10-12-2011
hi jim,
thanks for your great hint - it works perfectly.

here the complete line which works just perfectly for me:
Code:
date -d "$(grep 'some conditions' file_2_be_greped_from | awk 'BEGIN { FS="[|]*" } ; { print $3}')" +%s


Last edited by Franklin52; 10-12-2011 at 04:15 AM.. Reason: Please use code tags, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calculate Time diff in milli milliseconds(Time format : HH:MM:SS,NNN)

Hi All, I have one file which contains time for request and response. I want to calculate time difference in milliseconds for each line. This file can contain 10K lines. Sample file with 4 lines. for first line. Request Time: 15:23:45,255 Response Time: 15:23:45,258 Time diff... (6 Replies)
Discussion started by: Raza Ali
6 Replies

2. Post Here to Contact Site Administrators and Moderators

Display time in 12 hr format

Write a script named time that displays the time in standard 12-hour format, rather than 24-hour format. Allow the user to give a -m option to get 24-hour format. For example: > date Sun Feb 10 10:56:50 CST 2008 > time 10:56 AM > date Sun Feb 10 21:57:07 CST 2008 > time 9:57 PM >... (0 Replies)
Discussion started by: satish24
0 Replies

3. Shell Programming and Scripting

time format

Hello Guys. I have copied the following from the time man pages time -f "%E real,%U user,%S sys" ls -Fs But I am getting -f: command not found Regards (3 Replies)
Discussion started by: fdc2suxs
3 Replies

4. UNIX for Advanced & Expert Users

Convert to time format

I Have variable $currenttime and I want to display this variable as a TIME FORMAT and the $currenttime value contains like 000000 120000 020000 I want to display to 00:00:00 12:00:00 02:00:00 please help me how to this one (1 Reply)
Discussion started by: gksenthilkumar
1 Replies

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

6. Shell Programming and Scripting

help in time format

how to grep 30 mins from starting time of script let for example,script runs at 02:00am....i want to grep from 01.30 till 02:00 ------------------------------------------------------------------- how to achive this in a k-shell script ? (3 Replies)
Discussion started by: ali560045
3 Replies

7. Shell Programming and Scripting

time format..

HI.. I have some files...when doing "ls -l" its like this.. -rwxr-xr-x 1 e2e e2e 747 Aug 30 15:18 abc.txt how can I get the number YYYYMMDD from this...( since I need to compare this number with some other value..) with the help of date/awk/sed/epoch or whatever u... (1 Reply)
Discussion started by: clx
1 Replies

8. Shell Programming and Scripting

replace time format

Hello All, I have a problem with the following text file. For the field number 5 which is the time format (hh:mm:ss). But I would like to delete "ss" and showing hh:mm only. 00001,CLIENT,Company,1218,N,1:04,35,0.211,0,0.211,1.155531,0:00,0,0,0,0,0,1:04,35,0.211,0,0.211,1.155531,foold... (16 Replies)
Discussion started by: happyv
16 Replies
Login or Register to Ask a Question