Sponsored Content
Top Forums Shell Programming and Scripting Scan a file in realtime and execute certain commands on encountering 5 consecutive identical lines Post 302597100 by proactiveaditya on Thursday 9th of February 2012 07:43:43 AM
Old 02-09-2012
Question Scan a file in realtime and execute certain commands on encountering 5 consecutive identical lines

Mysql log has something like below:

Quote:
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
I need a bash shell script that will do the following:

1) The script will scan the mysql.log file constantly in real time (something like tail -F mysql.log)
2) If it encounters 5 consecutive identical lines then it would invoke some commands (say echo "yes")

Please help.

Last edited by proactiveaditya; 02-09-2012 at 08:53 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Cutting n consecutive lines from a file...

Hi, I have this problem of separating 10 consecutive lines from a file, say starting from 21 to 30... I have used a filter like this.. head -n 30 myfile | tail -n 10 Is there a simpler way than this? (2 Replies)
Discussion started by: Vishnu
2 Replies

2. UNIX for Dummies Questions & Answers

How to scan only new lines added in file?

Hi, I am planning to implement a scheduled script that will go against my log files (every hour), search for a set of key words (errors, exceptions, faults etc). The script must be intelligent enough to scan only the new lines added to the log file since it last ran. I can use grep for... (3 Replies)
Discussion started by: redlotus72
3 Replies

3. Shell Programming and Scripting

merging of 2 consecutive lines in a file for a specific pattern

Hi , I'm looking for a way to merge two lines only for a given pattern / condition. Input : abcd/dad + -49.201 2.09 -49.5 34 ewrew rewtre * fdsgfds/dsgf/sdfdsfasdd + -4.30 0.62 -49.5 45 sdfdsf cvbbv * sdfds/retret/asdsaddsa + ... (1 Reply)
Discussion started by: novice_man
1 Replies

4. Shell Programming and Scripting

Find time difference between two consecutive lines in same file.

Hello I have a file in following format: IV 08:09:07 NM 08:12:01 IC 08:12:00 MN 08:14:20 NM 08:14:15 I need a script to compare time on each line with previous line and show the inconsecutive line. Ex.: 08:12:00 08:14:15 A better way... (6 Replies)
Discussion started by: vilibit
6 Replies

5. Shell Programming and Scripting

how to delete two consecutive lines from the file

Hi guys I am deleting a unique line from the file and also need to remove the line above it which is NOT unique and servers as a record separator. Here is an example: # 101 803E 823F 8240 # 102 755f 4F2A 4F2B # 290 747D 0926 0927 # 999 8123 813E ... (5 Replies)
Discussion started by: aoussenko
5 Replies

6. Shell Programming and Scripting

finding and removing 2 identical consecutive words in a text

i want to write a shell script that correct a text file.for example if i have the input file: "john has has 2 apples anne has 3 oranges oranges" i want that the output file be like this: "john has 2 apples anne has 3 oranges" i've tried to read line by line from input text file into array... (11 Replies)
Discussion started by: cocostaec
11 Replies

7. Shell Programming and Scripting

Removing consecutive lines in a file

We have very large transaction logs that have transactions which start with a line that starts with 'Begin :' and ends with a line that starts with 'End :'. For most transactions there is valid data between those two lines. I am trying to get rid of lines that look like this: Begin :... (11 Replies)
Discussion started by: deneuve01
11 Replies

8. UNIX for Dummies Questions & Answers

Delete 26 consecutive lines in a file

I have a text file that is about 90,000 lines long. How would I delete lines 64-89, 152-177, 240-265, 328-353... etc? The sections I would like to delete are 26 lines long and the number of lines between the sections I would like to delete is 62 lines. Thanks very much in advance. (6 Replies)
Discussion started by: MDeBiasse
6 Replies

9. Shell Programming and Scripting

Grep 2 consecutive lines and replace the second line in a file

I have a file lake this cat ex1.txt </DISCOUNTS> <B2B_SPECIFICATION elem="0"> <B2B_SPECIFICATION elem="0"> <DESCR>Netti 2 </DESCR> <NUMBER>D02021507505</NUMBER> </B2B_SPECIFICATION> <B2B_SPECIFICATION elem="1"> <DESCR>Puhepaketti</DESCR>... (2 Replies)
Discussion started by: Dhoni
2 Replies

10. UNIX for Beginners Questions & Answers

awk - If field value of consecutive records are the identical print portion of lines

I have some data that looks like this: PXD= ZW< 1,6 QR> QRJ== 1,2(5) QR> QRJ== 4,1(2) QR> QRJ== 4,2 QRB= QRB 4,2 QWM QWM 6,2 R<C ZW< 11,2 R<H= R<J= 6,1 R>H XZJ= 1,2(2) R>H XZJ= 2,6(2) R>H XZJ= 4,1(2) R>H XZJ= 6,2 RDP RDP 1,2 What I would like to do is if fields $1 and $2 are... (5 Replies)
Discussion started by: jvoot
5 Replies
QPtrQueue(3qt)															    QPtrQueue(3qt)

NAME
QPtrQueue - Template class that provides a queue SYNOPSIS
#include <qptrqueue.h> Public Members QPtrQueue () QPtrQueue ( const QPtrQueue<type> & queue ) ~QPtrQueue () QPtrQueue<type> & operator= ( const QPtrQueue<type> & queue ) bool autoDelete () const void setAutoDelete ( bool enable ) uint count () const bool isEmpty () const void enqueue ( const type * d ) type * dequeue () bool remove () void clear () type * head () const operator type * () const type * current () const Protected Members virtual QDataStream & read ( QDataStream & s, QPtrCollection::Item & item ) virtual QDataStream & write ( QDataStream & s, QPtrCollection::Item item ) const DESCRIPTION
The QPtrQueue class is a template class that provides a queue. QValueVector can be used as an STL-compatible alternative to this class. A template instance QPtrQueue<X> is a queue that operates on pointers to X (X*). A queue is a first in, first out structure. Items are added to the tail of the queue with enqueue() and retrieved from the head with dequeue(). You can peek at the head item without dequeing it using head(). You can control the queue's deletion policy with setAutoDelete(). For compatibility with the QPtrCollection classes, current() and remove() are provided; both operate on the head(). See also QPtrList, QPtrStack, Collection Classes, and Non-GUI Classes. MEMBER FUNCTION DOCUMENTATION
QPtrQueue::QPtrQueue () Creates an empty queue with autoDelete() set to FALSE. QPtrQueue::QPtrQueue ( const QPtrQueue<type> & queue ) Creates a queue from queue. Only the pointers are copied; the items are not. The autoDelete() flag is set to FALSE. QPtrQueue::~QPtrQueue () Destroys the queue. Items in the queue are deleted if autoDelete() is TRUE. bool QPtrQueue::autoDelete () const Returns the setting of the auto-delete option. The default is FALSE. See also setAutoDelete(). void QPtrQueue::clear () Removes all items from the queue, and deletes them if autoDelete() is TRUE. See also remove(). uint QPtrQueue::count () const Returns the number of items in the queue. See also isEmpty(). type * QPtrQueue::current () const Returns a pointer to the head item in the queue. The queue is not changed. Returns 0 if the queue is empty. See also dequeue() and isEmpty(). type * QPtrQueue::dequeue () Takes the head item from the queue and returns a pointer to it. Returns 0 if the queue is empty. See also enqueue() and count(). void QPtrQueue::enqueue ( const type * d ) Adds item d to the tail of the queue. See also count() and dequeue(). type * QPtrQueue::head () const Returns a pointer to the head item in the queue. The queue is not changed. Returns 0 if the queue is empty. See also dequeue() and isEmpty(). bool QPtrQueue::isEmpty () const Returns TRUE if the queue is empty; otherwise returns FALSE. See also count(), dequeue(), and head(). QPtrQueue::operator type * () const Returns a pointer to the head item in the queue. The queue is not changed. Returns 0 if the queue is empty. See also dequeue() and isEmpty(). QPtrQueue<;type> & QPtrQueue::operator= ( const QPtrQueue<type> & queue ) Assigns queue to this queue and returns a reference to this queue. This queue is first cleared and then each item in queue is enqueued to this queue. Only the pointers are copied. Warning: The autoDelete() flag is not modified. If it it TRUE for both queue and this queue, deleting the two lists will cause double- deletion of the items. QDataStream &; QPtrQueue::read ( QDataStream & s, QPtrCollection::Item & item ) [virtual protected] Reads a queue item, item, from the stream s and returns a reference to the stream. The default implementation sets item to 0. See also write(). bool QPtrQueue::remove () Removes the head item from the queue, and returns TRUE if there was an item, i.e. the queue wasn't empty; otherwise returns FALSE. The item is deleted if autoDelete() is TRUE. See also head(), isEmpty(), and dequeue(). void QPtrQueue::setAutoDelete ( bool enable ) Sets the queue to auto-delete its contents if enable is TRUE and not to delete them if enable is FALSE. If auto-deleting is turned on, all the items in a queue are deleted when the queue itself is deleted. This can be quite convenient if the queue has the only pointer to the items. The default setting is FALSE, for safety. If you turn it on, be careful about copying the queue: you might find yourself with two queues deleting the same items. See also autoDelete(). QDataStream &; QPtrQueue::write ( QDataStream & s, QPtrCollection::Item item ) const [virtual protected] Writes a queue item, item, to the stream s and returns a reference to the stream. The default implementation does nothing. See also read(). SEE ALSO
http://doc.trolltech.com/qptrqueue.html http://www.trolltech.com/faq/tech.html COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. AUTHOR
Generated automatically from the source code. BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qptrqueue.3qt) and the Qt version (3.1.1). Trolltech AS 9 December 2002 QPtrQueue(3qt)
All times are GMT -4. The time now is 01:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy