LinuxQuestions.org
Help answer threads with 0 replies.
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, 05: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, 07:00 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 10: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 11:34 AM
Calculate Local Time in seconds omriar Linux - General 3 09-03-2010 09:54 PM
VB, 30 seconds of your time, please? rhoyerboat Programming 2 02-27-2007 01:26 PM
replace empty function from the old format to the new format powah Programming 4 07-12-2005 08:07 PM
get system time in mili-seconds how to onnyloh Programming 2 09-22-2004 01:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:36 PM.

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