0

I have a string test.cgi@action=<action-name>

<action-name> can be any string

I would like to replace the above string with <action-name>.html for all the occurrences within a file.

Can any one please let me know how I can proceed with this using a Perl script?

ps: I didn't get any response when i posted as a comment to existing message. So, I'm posting as a new message.

2
  • You've been a member over a year; you need to learn how to vote, and how to accept answers. Commented Jul 15, 2011 at 3:18
  • if <action-name> can be any string, how do you know where the end of the string is? Commented Jul 15, 2011 at 14:01

2 Answers 2

2

If it's a file, you could just use sed (assuming you're on some kind of *nix platform).

sed 's/test.cgi@action=/.html/g' file > output

or if you're feeling risky, you can edit the file in place.

sed -i 's/test.cgi@action=/.html/g' file
Sign up to request clarification or add additional context in comments.

1 Comment

By using this, if i have a string test.cgi@action=self, it is replaced as ".htmlself" but i'm expecting it to replace it as "self.html". Also, How can i do this using a perl program?.
1
use strict;
use warnings;
use 5.010;

my $string = <<'END_OF_STRING';
    test.cgi@action=xxxxxxxxxxx
    xxxxx test.cgi@action=aaaaaa
    yyyyyyyyyyytest.cgi@action=
END_OF_STRING


$string =~ s/test.cgi\@action=/.html/g;
print $string;


--output:--
    .htmlxxxxxxxxxxx
    xxxxx .htmlaaaaaa
    yyyyyyyyyyy.html

2 Comments

The output which i'm expecting is xxxxxxxxxxxxxxxx.html aaaaaayyyyyyyyyy.html
Does any one know how to modify script to get my expected output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.