How would I do 2 search & replaces in 1 Perl statement?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How would I do 2 search & replaces in 1 Perl statement?
# 1  
Old 04-15-2011
Question How would I do 2 search & replaces in 1 Perl statement?

Hi All,

The below code successfully tails the logfile.log file and colors every word "ERROR" in RED, thanks to the Perl statement below.

However, would anyone know how to append 1 additional search/replace to the Perl statement below, to color the word "SUCCESS" in GREEN (using ANSI \e[42;1m) ? I'd like to do this without piping to a 2nd perl statement, if possible.

Code:
  tail -f /var/log/logfile.log | perl -pe 's/ERROR/\e[41;1m$&\e[0m/g'

Thank you so much!
cg
(btw- DGPickett, thanks for your help in the other thread...I simplified the code over here to make this question easier to read)
# 2  
Old 04-15-2011
I think this should work for you:
Code:
tail -f /var/log/logfile.log | perl -pe 's/ERROR/\e[41;1m$&\e[0m/g;s/SUCCESS/\e[42;1m$&\e[0m/g'

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 04-15-2011
MySQL

Hi Bartus,

Wow. A semi-colon was all I needed. My gosh, I could streamline/improve so much of my past script knowing that now. Thank you so much for not only helping me out here, but in giving me a tip that will last as long as I'm scripting!

Thank you!
CG
# 4  
Old 04-20-2011
Can someone tell me where I can find all the ANSI codes for text editing ? I'm really new to all this so I'll appreciiate your input Smilie
Cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replaces a value in a file after a particular string using perl?

I need to replace the value of notifications_enabled to 0 if the value already set to 1 and vice versa(not the other values and spaces remain same after the value changed). I tried the below program for that. Can any one help me out. file:test.cfg define host { hostgroups ... (2 Replies)
Discussion started by: praveen265
2 Replies

2. Shell Programming and Scripting

Using && in if statement with 3 expressions

how do you write an if statement for something like if ((expr 1 >= expr 2 && expr 3 >= expr 4) && expr 5 <= expr 6) if ((TRUE && TRUE) && TRUE) then condition... i've done it this way but it doesn't seem to work. if (] && "$ex_day" -le "$curr_day" ); then condition... (3 Replies)
Discussion started by: angilulu
3 Replies

3. Shell Programming and Scripting

if statement with '&&' gives error

Hi, I'm using the && operator in if statement: if ; then exp $UID/$PWD@$ORACLE_SID FILE=./DUMP/$TODAY$CONCAT_STR$USERNAME.dmp STATISTICS=NONE LOG=./LOG/$TODAY$CONCAT_STR$USERNAME.log elif ; then expdp $UID/$PWD@$ORACLE_SID DIRECTORY=./DUMP/ DUMPFILE=$TODAY$CONCAT_STR$USERNAME.dmp... (8 Replies)
Discussion started by: priya001
8 Replies

4. Shell Programming and Scripting

Search and replaces lines with a variable number

Helo, I have a kml file with 39.000 lines. Need search text and add a sequential number before text. Original file <Placemark> <name>POI</name> <styleUrl>#waypoint</styleUrl> <Point> <coordinates>2.104510,41.341900</coordinates> </Point> ... (3 Replies)
Discussion started by: saba01
3 Replies

5. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

6. Shell Programming and Scripting

How to write If statement using && and operator in Unix

Hi What is the syntax for if statement using && and || operator? if && ] || here its giving me an error to this if statement any suggestion?? (2 Replies)
Discussion started by: Avi
2 Replies

7. Programming

IF && statement problem

Hello there, My first time on the forums, glad to be here :) I'm completely new to programming in PHP and I have a question which I hope someone could help me with. I am currently using this statement: if(($session == 2) && ($item == Dagger) && ($item2 == Dagger)){ ... (5 Replies)
Discussion started by: Hero
5 Replies

8. Shell Programming and Scripting

search & replace password perl script

I wanted a perl script to be done for Password search & replace in two files. For Example: Example 1)--i am having a file such as cat /opt/customer/Ariba/UAT/ariba/app/buyer/Server/config/Parameters.table Example 2)--and i am having a other file in other location such as cat... (4 Replies)
Discussion started by: shellscript22
4 Replies

9. Shell Programming and Scripting

if statement with two conditions -e, &&

Wow I'm so zoned out I don't even know if I posted this question up already (I couldn't find it in my book marks or in "yesterday's" post). My question is, I'm writing a korn script that does something like the following, but I don't yet completely understand the syntax. I need to check that... (16 Replies)
Discussion started by: yongho
16 Replies

10. Shell Programming and Scripting

Using varible/varible substitution in Perl/sed Search & Replace

Hi, I have a program that searches for a particular string patten. I am however having difficulty passing the varible $i (in a loop) as the string pattern to replace. Using either perl or sed search and replace statements, I get the same kinda result. For example, using the perl: for i in... (3 Replies)
Discussion started by: Breen
3 Replies
Login or Register to Ask a Question