LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-21-2010, 03:28 AM   #1
smc2
LQ Newbie
 
Registered: Apr 2010
Posts: 29

Rep: Reputation: 0
Question 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..

Last edited by smc2; 10-21-2010 at 03:32 AM.
 
Old 10-21-2010, 05:21 AM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
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.
 
1 members found this post helpful.
Old 10-21-2010, 05:27 AM   #3
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
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.
 
  


Reply

Tags
perlscript


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help scripting to find line and print previous line to out jamieofansa Programming 4 05-21-2010 01:30 PM
Scripting question - feed an input file into an if statement line-by-line kmkocot Linux - Newbie 10 01-18-2010 11:49 AM
need to delete a line if a field of that line matches using awf in bash scripting accesskarthi Linux - Newbie 8 06-29-2009 03:15 AM
Shell scripting: print first line and last line only Micro420 Programming 5 05-20-2007 06:26 PM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 10:24 PM


All times are GMT -5. The time now is 02:50 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration