LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Perl one-line scripting: Some problems (https://www.linuxquestions.org/questions/programming-9/perl-one-line-scripting-some-problems-839488/)

smc2 10-21-2010 03:28 AM

Perl one-line scripting: Some problems
 
I'm trying to highlight some key words as tailing a log file using a perl script;
about my case:
  1. I want to search for a keyworrs just once and highligt all occurrence of them.
  2. I want just highlit the keywords but not the whole line

but the problems are that
  1. perl just catches the first keyword in a line and skip checking for other occurrence. for example if a line like "Error: some exception happen, Unable to process" it just highlight the error and do not process the remain part of the line where it should hilight the word "exception" and "Unable"
  2. 2-How can I do some action if for exapmle at least 4 time "unable" message appear ( not just in one line but diffrent line)in


below is how I use perl search and replace :

Code:

s/(?:(unable|exception|warning))/\e[1;31$&.......

Thanks in Advance..

crts 10-21-2010 05:21 AM

Hi,

I am not familiar with perl, so not sure if this might help. However, does the 's' command support the 'g' flag? Did you try to set it at the end like
Code:

s/.../.../g
This *might* do what you want if 's' in perl works similiar as e.g. in sed.

estabroo 10-21-2010 05:27 AM

For the second part you might want to go away from a one-liner, add another line that checks for the keyword and increments a counter if it's there and then calls a function when you hit 4 (or whatever), probably want to clear the counter after calling the function. Just put this check before your substituion.


All times are GMT -5. The time now is 07:25 AM.