04-16-2009
Perl search and replace file content.
I am not sure if this is doable. I am trying to open and print the content of the file by replacing all instances fo perl to PERL . This is my code but it is
giving me the number count instead of the actual lines with changes.
open (PERLHISTORY, 'sample.txt') or die "The file sample.txt could not be found\n";
@B = <PERLHISTORY>; #Reads the whole line
while ($Line = shift(@B))
{
$NewLine = ($Line =~ s/perl/PERL/gi);
print $NewLine; # This gives a count not the actual changed line
}
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi All,
I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text.
An example of 4 lines in my file is:
1. MatchText_randomNumberOfText moreData ReplaceMe moreData
2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
2. Shell Programming and Scripting
I am very new to Perl. I am struggling so hard to search a date (such as 10/09/2009, 10-09-2009) from a text file and replace with a string (say DATE) using Perl. Please help me out. Thanks in advance.
Regds
Doren (4 Replies)
Discussion started by: my_Perl
4 Replies
3. Shell Programming and Scripting
Hi All,sorry for inconvience....please find the attachement for my question i am unable to paste the question here....please help me in slving thisthanksk.k (4 Replies)
Discussion started by: G.K.K
4 Replies
4. Shell Programming and Scripting
Hello All,
Here is what I am trying to do and maybe you guys can point me in the right direction. I have a file that contains the following string(s):
WARNING: </d1/test/program1> did not find item1
WARNING: </d1/test/program1> item1 does not exist
WARNING: </d1/test/program2> item1 failed... (1 Reply)
Discussion started by: maxshop
1 Replies
5. Shell Programming and Scripting
HI
I'm terribly new to perl .. I;ve been trying to use this command to search and replace entries in a file
I tried this and it works
perl -p -i -e 's/old/new/' filename
Problem is that I have a list of email addresses and I need to serach and replace the entire email address as my... (5 Replies)
Discussion started by: mnassiri
5 Replies
6. Shell Programming and Scripting
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)
Discussion started by: sasharma
4 Replies
7. Shell Programming and Scripting
Hi,
I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C.
Thanks a lot!!
Here is a sample of my question.
e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 Replies
8. Shell Programming and Scripting
Hi,
I have two files master.txt & reference.txt. Sample below
Master.txt
2372,MTS,AP
919848001104,Airtel,DL
0819,MTS,MUM
919849788001,Airtel,AP
1430,Aircel MP,20
Reference.txt
2372,919848701430,46467
919848002372,2372,47195
2372,919849788001,59027
0819,028803,1
0819,029801,1... (2 Replies)
Discussion started by: siramitsharma
2 Replies
9. Shell Programming and Scripting
Hi,I have 2 files master.txt & reference.txt as shown below & i require o/p as mentioned in file 3 using awk but content is not replacing properlymaster.txt:... (15 Replies)
Discussion started by: siramitsharma
15 Replies
10. Shell Programming and Scripting
How can I achieve this? Perl would be awesome.
Input string a_b c //Note there is a blank here
Needed Output a_b_c
Thanks (4 Replies)
Discussion started by: dragonpoint
4 Replies
LEARN ABOUT DEBIAN
devel::patchperl::hints
Devel::PatchPerl::Hints(3pm) User Contributed Perl Documentation Devel::PatchPerl::Hints(3pm)
NAME
Devel::PatchPerl::Hints - replacement 'hints' files
VERSION
version 0.72
SYNOPSIS
use Devel::PatchPerl::Hints;
if ( my $content = Devel::PatchPerl::Hints->hint_file() ) {
chmod 0644, 'hints/netbsd.sh' or die "$!";
open my $hints, '>', 'hints/netbsd.sh' or die "$!";
print $hints $content;
close $hints;
}
DESCRIPTION
Sometimes there is a problem with Perls "hints" file for a particular perl port. This module provides fixed "hints" files encoded using
"MIME::Base64".
FUNCTION
The function is exported, but has to implicitly imported into the requesting package.
use Devel::PatchPerl::Hints qw[hint_file];
It may also be called as a class method:
use Devel::PatchPerl::Hints;
my $content = Devel::PatchPerl::Hints->hint_file();
"hint_file"
Takes an optional argument which is the OS name ( as would be returned by $^O ). By default it will use $^O.
In a scalar context, Will return the decoded content of the "hints" file suitable for writing straight to a file handle or undef list
if there isn't an applicable "hints" file for the given or derived OS.
If called in a list context, will return a list, the first item will be the name of the "hints" file that will need to be amended, the
second item will be a string with the decoded content of the "hints" file suitable for writing straight to a file handle. Otherwise an
empty list will be returned.
AUTHOR
Chris Williams <chris@bingosnet.co.uk>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Chris Williams and Marcus Holland-Moritz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
perl v5.14.2 2012-06-04 Devel::PatchPerl::Hints(3pm)