I have three variables $a, $b and $c
$a = file_abc_123.txt
$b = 123
$c = 100
I want to search if $b is present in $a. If it is present, then i want to replace that portion by $c.
Here $b = 123 is present in "file_abc_123.txt", so i need the output as "file_abc_100.txt'
How can this be done.
Thanks in advance
zaxxon
November 2, 2011, 5:24am
2
Which shell or scripting language do you use and what have you tried so far?
perl. I tried using pattern matching.
---------- Post updated at 04:44 AM ---------- Previous update was at 04:26 AM ----------
can you give an idea on this plz
---------- Post updated at 04:44 AM ---------- Previous update was at 04:44 AM ----------
can you give an idea on this plz
---------- Post updated at 04:58 AM ---------- Previous update was at 04:44 AM ----------
birei
November 2, 2011, 10:25am
4
Hi irudayaraj,
Try:
$ cat script.pl
use warnings;
use strict;
my $a = "file_abc_123.txt";
my $b = 123;
my $c = 100;
if ( $a =~ m/$b/ ) {
$a =~ s/$b/$c/;
}
printf "%s\n", $a;
$ perl script.pl
file_abc_100.txt
Regards,
Birei