clip selective text and minus


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting clip selective text and minus
# 1  
Old 02-27-2008
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  
Old 02-28-2008
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

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Programming

Clip mask on all screen

Hello everyone. I'm programming in C with xlib (standart libs). I need set GC with transparent pixmap (in some pixels). I have colored pixmap, that set tile for GC via XSetTile. This pixmap is painted on all screen. And I have mask, created by this pixmap. This mask is set by XSetClipMask. But... (1 Reply)
Discussion started by: Yuriy
1 Replies

2. Shell Programming and Scripting

sed help, Find a pattern, replace it with same text minus leading 0

HI Folks, I'm looking for a solution for this issue. I want to find the Pattern 0/ and replace it with /. I'm just removing the leading zero. I can find the Pattern but it always puts literal value as a replacement. What am I missing?? sed -e s/0\//\//g File1 > File2 edit by... (3 Replies)
Discussion started by: SirHenry1
3 Replies

3. UNIX for Advanced & Expert Users

trim 165 MB video clip with ffmpeg (only last 3 minutes)

Hi original video clip > ls -alh reallynotpr0n.flv -rw-r--r-- 1 jonny staff 165M Nov 18 19:57 reallynotpr0n.flvtrying to cut only last 3 minutes of the clip out. > ffmpeg -i reallynotpr0n.flv -vcodec copy -acodec copy -ss 00:52:00 -t 00:03:48 trimmed_video.avi ffmpeg version 0.7.7,... (3 Replies)
Discussion started by: slashdotweenie
3 Replies

4. Shell Programming and Scripting

Copy selective lines from text file

Hello, I have a text file which I need to check for presence of certain tags, and then copy a subsequent portion of text into another file. The tag matching canbe done with Grep but I do not know how to copy selective lines from one file to another. Is it possible do that? I checked up some... (8 Replies)
Discussion started by: ajayram
8 Replies

5. Shell Programming and Scripting

selective replacing text using sed/perl

Hi, I have the following text which I want to search and replace using perl and sed. I would appreciate any help. Please notice the file contains schema name with a single dot and a double dot . &&WEBDIR_SCHEMA. and &&WEBDIR_SCHEMA .. } I would like to change it to the acutal schema... (5 Replies)
Discussion started by: jville
5 Replies

6. UNIX for Dummies Questions & Answers

Is there any non graphical tool that make selective merge between text files?

whitout using awk / sad and so on? (3 Replies)
Discussion started by: umen
3 Replies

7. UNIX for Advanced & Expert Users

Clearing paste/clip board

Hello..... Is there anyway that I can clear the clipboard/paste/buffer in UNIX, Xterm, telnet? I have a number of scripts that require values being inputted correctly by the user. I have nothing to validate the values so I have to put trust in their ability to cut/paste correctly. :rolleyes: ... (4 Replies)
Discussion started by: nhatch
4 Replies
Login or Register to Ask a Question