The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Minus of 2 files -- Please help tipsy Shell Programming and Scripting 7 05-13-2009 05:14 PM
minus sign trichyselva UNIX for Dummies Questions & Answers 2 03-03-2008 11:00 AM
Is there any non graphical tool that make selective merge between text files? umen UNIX for Dummies Questions & Answers 3 08-25-2005 03:22 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-27-2008
srini123 srini123 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 1
clip selective text and minus

After doing some scripting in a log file, I am left with some lines like this.

10:00:00 Received Message Message ID 1
10:05:00 Published Message Message ID 1
10:10:00 Received Message Message ID 2
10:15:00 Published Message Message ID 2
10:20:00 Received Message Message ID 3
10:26:00 Published Message Message ID 3
10:30:00 Received Message Message ID 4
10:37:00 Published Message Message ID 4
10:40:00 Received Message Message ID 5
10:48:00 Published Message Message ID 5


I would like to have my output like this (difference between received and published messages with message id)

Message ID 1: 5
Message ID 2: 5
Message ID 3: 6
Message ID 4: 7
Message ID 5: 8

Any simple direct shell script for this?
  #2 (permalink)  
Old 02-28-2008
robotronic's Avatar
robotronic robotronic is online now Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
I suppose the time format is "hh:mm:ss" and you want the output expressed in minutes:


Code:
awk '
   {
      if (++x[$NF]>1) {
         split($1,curr_time,":");
         interval=(curr_time[1]*3600+curr_time[2]*60+curr_time[3]) - \
                  (prev_time[1]*3600+prev_time[2]*60+prev_time[3]);
         print("Message ID "$NF": "interval/60);
      } else {
         split($1,prev_time,":");
      }
   }
' input_file

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0