Print events from two lines with a common identifier | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Print events from two lines with a common identifier

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-21-2013
vanand420 vanand420 is offline
Registered User
 
Join Date: Jul 2005
Last Activity: 27 June 2013, 9:52 AM EDT
Posts: 98
Thanks: 13
Thanked 1 Time in 1 Post
Print events from two lines with a common identifier

Hi Unix Gurus,

I have a long text file, where alarms events are logged and alarm clear event are logged.

Both events alarm and alarm clear has common identifier as{xxxxxxxxxx}

I need to analyse the time-period for which the alarm sustained.

i.e

Output: timestamp from both event has been captured.

Code:
alarm;  pcm;     communications; major;  2013-06-21 03:23:00; 2013-06-21 03:23:03;    {1006905493};

Input File:

Code:
alarm;  pcm;     communications; major;  2013-06-21 03:23:00;     {1006905493};   '2.2.2.1-pcmBlock-X';
clearAlarm;     pcm;     communications; major;  2013-06-21 03:23:03;     {1006905493};   autoclear;
alarm;  pcm;     communications; major;  2013-06-21 03:23:04;     {1006905494};   '2.2.2.1-pcmBlock-X';
clearAlarm;     pcm;     communications; major;  2013-06-21 03:23:09;     {1006905494};   autoclear;

Thanks in advance..
Sponsored Links
    #2  
Old 06-21-2013
rbatte1 rbatte1 is offline Forum Staff  
Moderator
 
Join Date: Jun 2007
Last Activity: 24 October 2014, 3:13 PM EDT
Location: Lancashire, UK
Posts: 1,869
Thanks: 599
Thanked 322 Times in 290 Posts
So, just to get the logic right first:-
  • You want to get the start record of an alarm and grab the first five fields
  • You want to append the clear-alarm record fields 5 & 6
If this is true, then it depends on the volume of data as to weather it is easier to write a shell script with greps or a more complex awk

You could:-
  • Get a list of all the common identifiers then use grep to get those records and blend them together.
  • Split the record into two files, strip out the fields you don't want then use paste

There are probably plenty of other ways too. What are your thoughts on this?



Robin
Liverpool/Blackburn
UK
Sponsored Links
    #3  
Old 06-21-2013
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Advisor  
The Tutor
 
Join Date: Jun 2008
Last Activity: 9 April 2014, 1:31 AM EDT
Location: INDIA, Bangalore
Posts: 2,049
Thanks: 16
Thanked 106 Times in 102 Posts
try..

Code:
 
 
awk -F";" '/^alarm/{split($5,A," ");
getline;
split($5,B," ");
split(A[2],C,":");
split(B[2],D,":");
E=(D[1]*60*60+D[2]*60+D[3])-(C[1]*60*60+C[2]*60+C[3]);
{if(E>59){print "Alarm ID"$6" clearded in "(E%3600)/60" minutes"}else{print "Alarm ID"$6" clearded in "E" seconds"}}}' filename


Last edited by vidyadhar85; 06-21-2013 at 05:38 AM..
The Following User Says Thank You to vidyadhar85 For This Useful Post:
vanand420 (06-21-2013)
    #4  
Old 06-21-2013
vanand420 vanand420 is offline
Registered User
 
Join Date: Jul 2005
Last Activity: 27 June 2013, 9:52 AM EDT
Posts: 98
Thanks: 13
Thanked 1 Time in 1 Post
Quote:
Originally Posted by vidyadhar85 View Post
try..

Code:
 
 
awk -F";" '/^alarm/{split($5,A," ");
getline;
split($5,B," ");
split(A[2],C,":");
split(B[2],D,":");
E=(D[1]*60*60+D[2]*60+D[3])-(C[1]*60*60+C[2]*60+C[3]);
{if(E>59){print "Alarm ID"$6" clearded in "(E%3600)/60" minutes"}else{print "Alarm ID"$6" clearded in "E" seconds"}}}' filename

Thanks Man!! It worked like a rocket..perfect..!!
Made few changes to script i.e. added sort -t ';' -k6 {to sort the common identifier in order means alarm then corresponding clearAlarm else alarm and corresponding ClearAlarm are most of the times far in file, not next line}

How this script would react if a alarm is not clear i.e it does not have a clearAlarm event? What has to be modified in it..

Thanks for your support!!
The Following User Says Thank You to vanand420 For This Useful Post:
rbatte1 (06-21-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find common numbers and print yes or no manigrover Shell Programming and Scripting 1 09-21-2012 11:23 AM
print lines AFTER lines cointaining a regexp (or print every first and fourth line) kmkocot Shell Programming and Scripting 1 07-06-2010 09:57 PM
Common lines from files jaysean Shell Programming and Scripting 5 06-29-2010 03:19 AM
how to take out common of two lines in a file jam_ali49 UNIX for Advanced & Expert Users 6 11-23-2007 03:48 AM
COMMON_ROOT=/files/common: is not an identifier nitinmoriwal UNIX for Advanced & Expert Users 2 08-25-2006 08:38 AM



All times are GMT -4. The time now is 07:09 PM.