Sponsored Content
Top Forums Shell Programming and Scripting Script to count matched string then check again from last read position Post 302990147 by nms on Monday 23rd of January 2017 05:00:05 AM
Old 01-23-2017
Script to count matched string then check again from last read position

Hi all,

I am currently trying to figure out how can i capture a particular string from a log file, then search again but from the last line it read before onward.
Basically let's say that the check runs every 5 mins via cron, counting the number of matched strings "Cannot assign requested address" from the log sample below:

Code:
Nov 28 18:18:09.005100 diameterControlAgent(3426) NOTICE: {960112} Peer: 'jinny': adding permitted origin host 'AM1RTC01.NL.ASPIDERSOLUTIONS.COM'
Nov 28 18:18:09.005649 diameterControlAgent(3426) NOTICE: {960112} Peer: 'jinny': adding permitted origin host 'AM1RTC02.NL.ASPIDERSOLUTIONS.COM'
Nov 28 18:18:09.009531 diameterControlAgent(3426) NOTICE: {960113} Peer: 'jinny': adding Remote Address '<ip address>'
Nov 28 18:18:09.010373 diameterControlAgent(3426) NOTICE: {960113} Peer: 'jinny': adding Remote Address 'ip address>'
Nov 28 18:18:09.010873 diameterControlAgent(3426) NOTICE: {960114} Loading peer: 'jinny': netmaskBits: 32
Nov 28 18:18:09.011362 diameterControlAgent(3426) NOTICE: {960115} Loading peer: 'jinny': permittedInstances: 0
Nov 28 18:18:09.011981 diameterControlAgent(3426) NOTICE: {960116} Loading peer: 'jinny': reqSctpInboundStreams: 8
Nov 28 18:18:09.012590 diameterControlAgent(3426) NOTICE: {960117} Loading peer: 'jinny': reqSctpOutboundStreams: 8
Nov 28 18:18:09.014542 diameterControlAgent(3426) NOTICE: {960013} Configuration Loaded
Nov 28 18:18:09.016790 diameterControlAgent(3426) ERROR: {969108} tcp:::<ip address:port>: bind to <ip address:port> failed: Cannot assign requested address.

The next time the script runs again, the aim is to continue searching for this string from the last "line" (i.e end of file) it read previously.

Hence either using AWK or grep -c. The problem s is how to make the script intelligent enough to search from the last read line onward. The log file changes continuously.

is it possible to achieve this?

I was thinking maybe using either the tail command to store the output then match it, but am afraid that most probably there would be similar matches.
Else maybe try a word count?

Do you have ideas?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

read string, check string length and cut

Hello All, Plz help me with: I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies

2. Shell Programming and Scripting

Read string from a file,plz help me to check

#!/usr/bin/ksh exec 0<property while read newReceiveDir do if then sed -e 's//home/joshua/bodi/data/receive/{$newReceiveDir:25}/g/' mp_validate.sh >| mp_validate.sh elif then sed -e 's//home/joshua/bodi/data/temp/{$newReceiveDir:22}/g/' mp_validate.sh >| mp_validate.sh ... (1 Reply)
Discussion started by: joshuaduan
1 Replies

3. UNIX for Dummies Questions & Answers

Count of matched pattern occurance

In a file a pattern is occured many times randomly. Even it may appear more then once in the same line too. How i can get the number of times that pattern appeared in the file? let the file name is abc.txt and the pattern is "xyz". I used the following code: grep -ic "xyz" abc.txt but it is... (3 Replies)
Discussion started by: palash2k
3 Replies

4. Shell Programming and Scripting

how to find a position and print some string in the next and same position

I need a script for... how to find a position of column data and print some string in the next line and same position position should find based on *HEADER8* in text for ex: ord123 abs 123 987HEADER89 test234 ord124 abc 124 987HEADER88 test235 ... (1 Reply)
Discussion started by: naveenkcl
1 Replies

5. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

6. Shell Programming and Scripting

Script To read Date and count from files

Smaple 1 Date and Time: 2013-05-11 12:23:12 MST abc,1234,hi-all,45354-88888,IN,US XYZ,1234,hi-all,45354-88888,OUT,GB abc,1234,hi-all,45354-88888,IN,AS abc,1234,hi-all,45354-88888,OUT,US abc,1234,hi-all,45354-88888,IN,US Number of Records: 000005 Sample 2 HDR: 20130511... (1 Reply)
Discussion started by: Abhisrajput
1 Replies

7. Shell Programming and Scripting

Write a word at 72nd position of a matched line in a file

Hi, I need to search a file for a pattern,replace some other word and write a word at its 72nd position. For example, My name is Mano.Im learning Unix. I want to search the file in all lines containing the word "Mano".In that matched line,replace the word "Unix" with "Java".And... (5 Replies)
Discussion started by: mano1 n
5 Replies

8. UNIX for Dummies Questions & Answers

I need a Script to read Log string and check date at the same time

I need to check 1 log file, which is logging: 2014-08-18T09:10:39+02:00 user: XXXXX START FEATURE 2014-08-18T09:10:39+02:00 user: XXXXX FINISH FEATURE I first need to check that the START FEATURE starts and finish on the same time/date for the same user, which is different each time START... (2 Replies)
Discussion started by: TheBest43
2 Replies

9. Shell Programming and Scripting

Search for a string at a particular position and replace with blank based on position

Hi, I have a file with multiple lines(fixed width dat file). I want to search for '02' in the positions 45-46 and if available, in that lines, I need to replace value in position 359 with blank. As I am new to unix, I am not able to figure out how to do this. Can you please help me to achieve... (9 Replies)
Discussion started by: Pradhikshan
9 Replies

10. UNIX for Beginners Questions & Answers

Count exact matched words

hi , i have a file test.dat which contains following data. test.dat XY|abc@xyz.com XY|abc@xyz.com ST|abc@xyz.com ST|abc@xyz.com ST|XYZ@abc.com FK|abc@xyz.com FK|STG@xyz.com FK|abc@xyz.com FK|FKG@xyz.com i want to know the count of XY,ST,FK. i.e XY = 2 , ST = 3 , FK = 4 I am... (4 Replies)
Discussion started by: itzkashi
4 Replies
PCAP_CAN_SET_RFMON(3PCAP)												 PCAP_CAN_SET_RFMON(3PCAP)

NAME
pcap_can_set_rfmon - check whether monitor mode can be set for a not-yet-activated capture handle SYNOPSIS
#include <pcap/pcap.h> int pcap_can_set_rfmon(pcap_t *p); DESCRIPTION
pcap_can_set_rfmon() checks whether monitor mode could be set on a capture handle when the handle is activated. RETURN VALUE
pcap_can_set_rfmon() returns 0 if monitor mode could not be set, 1 if monitor mode could be set, PCAP_ERROR_NO_SUCH_DEVICE if the capture source specified when the handle was created doesn't exist, PCAP_ERROR_PERM_DENIED if the process doesn't have permission to check whether monitor mode could be supported, PCAP_ERROR_ACTIVATED if called on a capture handle that has been activated, or PCAP_ERROR if an error occurred. If PCAP_ERROR is returned, pcap_geterr() or pcap_perror() may be called with p as an argument to fetch or display the error text. SEE ALSO
pcap(3PCAP), pcap_create(3PCAP), pcap_activate(3PCAP), pcap_set_rfmon(3PCAP) 18 May 2010 PCAP_CAN_SET_RFMON(3PCAP)
All times are GMT -4. The time now is 08:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy