1
set release=//packages/thirdparty/release/main.txt

perl -pe"s!(//packages/thirdparty/release/main.txt *)#\d+!$1#15!;" testlog.txt

How can I use %release% (environment variable release) instead of //packages/thirdparty/release/main.txt?

I'm getting syntax error from

 perl -pe"s!(%release%! *)#\d+!$1#15!;" testlog.txt

original question Search and replace a string using Windows shell or Perl script

1
  • Avinash, thank you for your help but answer provided by "Borodin" worked. Commented Mar 17, 2015 at 14:36

1 Answer 1

3

You can use the %ENV hash to access environment variables, like this

perl -pe"s/(\Q$ENV{RELEASE}\E *)#\d+/$1#15/" testlog.txt

You can also use a positive look-behind to avoid having to replace the initial string

perl -pe"s/(?<=\Q$ENV{RELEASE}\E *)#\d+/#15/" testlog.txt

or \K if you are running version 14 or later of Perl 5

perl -pe"s/\Q$ENV{RELEASE}\E *\K#\d+/#15/" testlog.txt
Sign up to request clarification or add additional context in comments.

Comments

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.