find and replace string as comment using perl

Suppose there is file abx.txt. Need to comment (with #) line having text contain “test”.
i.e
abc.txt:
this is test
test is this
this test is this
nothing to comment

output:
#this is test
#test is this
#this test is this
nothing to comment

code:
open FH, "<abc.txt";
while()
{
my $str= $_;
$str =~/(?=.*\btest\b)/#/;
print $str;
}

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: