Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 10-21-2010, 04:28 AM   #1
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 :


Thanks in Advance..

Last edited by smc2; 10-21-2010 at 04:32 AM.
Old 10-21-2010, 06:21 AM   #2
Senior Member
Registered: Jan 2010
Posts: 1,620

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451

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
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, 06:27 AM   #3
Senior Member
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,125
Blog Entries: 2

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



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 02:30 PM
Scripting question - feed an input file into an if statement line-by-line kmkocot Linux - Newbie 10 01-18-2010 12:49 PM
need to delete a line if a field of that line matches using awf in bash scripting accesskarthi Linux - Newbie 8 06-29-2009 04:15 AM
Shell scripting: print first line and last line only Micro420 Programming 5 05-20-2007 07:26 PM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 11:24 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:16 AM.

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