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
script:
Moderator's Comments:
Please use code tags next time for your code and data.
Last edited by Scott; 01-30-2013 at 09:01 AM..
Reason: vbe: code tags - format... Using code tags preserve the format you know...; Scott: Removed poll
Hi All,
I need to search for a string in a file that I've opened and base a decision on the result. The logic is this:
"if the word 'Shared' appears on the first line then
do this on the whole file
else
do this on the whole file
"
The code I currently have isn't working:... (4 Replies)
Looking for a bit of help. I need to search for a string of words, but unfortunately these words are located on separate lines.
for example the text output is:
United
Chanmpions
Ronaldo
Liverpool
Losers
Torres
and my script code is
print("DEBUG - checking file message");
while... (15 Replies)
Hi,
This is the first time playing around with perl and need some help.
Assuming if i have a line of text that looks like this:
Date/Time=Nov 18 17:12:11;Device Name=192.168.1.1;Device IP=192.168.1.1;Device Class=IDS;Source IP=155.212.212.111;Source Name=UNKNOWN;Source Port=1679... (3 Replies)
Is it possible, Using Perl script, to exit the program, when I get the first occurrence of a string. For eg, if I get a string "break" in a file (during parsing), i want to exit !
I tried using "filehandle". giving the string and file-name as commandline arguments. (3 Replies)
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
... (3 Replies)
Hi Guys
In perl how can i look for a string in side a file and return something if it exists
a little bit of background i have made a wrapepr for a program but in order for the program to work i need to modify a file first, i want to stick something in the wrapper that will tell if the sting... (1 Reply)
Hi
I would like to read a file using perl and search for a string (last entry). Then read that into an array and do further grep
File content for ex:
comp=a,value=30,runtime=12,type=lic
comp=d,value=15,runtime=2,type=lic
comp=a,value=90,runtime=43,type=lic... (1 Reply)
Dear all,
I have a number of files and each file has two sections separated by a blank line. At the top section, I have lines which describes the values of the alphabetical characters,
# s #; 0.123
# p #; 12.3
# d #; -2.33
# f #; 5.68
<blank line>
sssssss
spfdffff
sdfffffff
Now I... (4 Replies)
I have file which contains a huge amount of data. I need to search the pattern Message id. When that pattern is matched I need to get abcdeff0-1g6g-91g3-1z2z-2mm605m90000 to another file.
Kindly provide your input.
File is like below
Jan 11 04:05:10 linux100 |NOTICE... (2 Replies)
Hello Forum.
I have a file called abc.sed with the following commands;
s/1/one/g
s/2/two/g
...
I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat
sed -f abc.sed abc.dat >... (10 Replies)
Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismUsereContributedPerl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators(3)NAME
Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators - Don't mix numeric operators with string operands, or vice-versa.
AFFILIATION
This Policy is part of the core Perl::Critic distribution.
DESCRIPTION
Using the wrong operator type for a value can obscure coding intent and possibly lead to subtle errors. An example of this is mixing a
string equality operator with a numeric value, or vice-versa.
if ($foo == 'bar') {} #not ok
if ($foo eq 'bar') {} #ok
if ($foo eq 123) {} #not ok
if ($foo == 123) {} #ok
CONFIGURATION
This Policy is not configurable except for the standard options.
NOTES
If warnings are enabled, the Perl interpreter usually warns you about using mismatched operators at run-time. This Policy does essentially
the same thing, but at author-time. That way, you can find out about them sooner.
AUTHOR
Peter Guzis <pguzis@cpan.org>
COPYRIGHT
Copyright (c) 2006-2011 Peter Guzis. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license
can be found in the LICENSE file included with this module.
perl v5.16.32014Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators(3)