LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-30-2011, 06:54 AM   #1
murke
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Rep: Reputation: 0
Replace time format to seconds?


Hi all,

I have log file in format

Jun/26/2011 01:17:50 wireless ....
Jun/26/2011 18:25:15 wireless ....
Jun/26/2011 22:34:43 wireless ....

I need to put this in format ( only seconds insted hours:minutes:secondes)

Jun/26/2011 4670s wireless ....
Jun/26/2011 66315s wireless ....
Jun/26/2011 81283s wireless ....
If i use
awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }' output iz only 4670,66315,81283....
I try to use something like
sed "s/ \([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\ \)/`awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }'` /g"
but doesn't work
Thanx
 
Old 06-30-2011, 08:00 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Hi and welcome to LinuxQuestions!
Code:
awk '{split($2,time,":"); print time[1] * 3600 + time[2] * 60 + time[3]}' file
If you want to re-print the whole file:
Code:
awk '{ split($2,time,":"); $2 = time[1] * 3600 + time[2] * 60 + time[3] }1' file
 
1 members found this post helpful.
Old 06-30-2011, 11:22 AM   #3
murke
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thanx
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
convert total no of seconds in the format hour minutes and seconds suchi_s Programming 15 03-15-2011 12:34 PM
Calculate Local Time in seconds omriar Linux - General 3 09-03-2010 10:54 PM
VB, 30 seconds of your time, please? rhoyerboat Programming 2 02-27-2007 02:26 PM
replace empty function from the old format to the new format powah Programming 4 07-12-2005 09:07 PM
get system time in mili-seconds how to onnyloh Programming 2 09-22-2004 02:52 PM


All times are GMT -5. The time now is 06:12 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration