CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Perl find and replace

 



venhart
New User

Sep 14, 2011, 8:03 AM

Post #1 of 7 (1685 views)
Perl find and replace Can't Post

Hi,

Please could someone advise, how I can resolve this issue with my find and replace command :

perl -i -npe "s#RLM_LICENSE.*#RLM_LICENSE=$TEAM_TOP/licenses/abc.demo.lic#;" environment.properties

$TEAM_TOP is an environment varible within my system.

when i run this perl command from a script and check the environment.properties file. It displays the full path of $TEAM_TOP

e.g.

RLM_LICENSE=/team/dev6/data/REL1_TOP/licenses/abc.demo.lic

and

I would need it to show this instead :

RLM_LICENSE=$TEAM/licenses/abc.demo.lic

thank you


rovf
Veteran

Sep 15, 2011, 3:21 AM

Post #2 of 7 (1637 views)
Re: [venhart] Perl find and replace [In reply to] Can't Post

Your question is not fully clear to me. Could you please post

- The value of the environment variable TEAM_TOP
- The affected line in environment.properties prior to substitution


venhart
New User

Sep 15, 2011, 3:42 AM

Post #3 of 7 (1635 views)
Re: [rovf] Perl find and replace [In reply to] Can't Post

Hi,

The value of the environment variable TEAM_TOP is :

$TEAM_TOP=/team/dev6/data/REL1_TOP

The affected line in environment.properties prior to substitution is :

RLM_LICENSE=

I need this to look like :

RLM_LICENSE=$TEAM/licenses/abc.demo.lic

and not like :

RLM_LICENSE=/team/dev6/data/REL1_TOP/licenses/abc.demo.lic

thankyou


rovf
Veteran

Sep 15, 2011, 4:04 AM

Post #4 of 7 (1633 views)
Re: [rovf] Perl find and replace [In reply to] Can't Post

Since the substitution string is not related to your TEAM_TOP environment variable, I wonder why, then, you use this variable in substitution.

I conclude from your code that you are running on some standard shell on Linux/Unix. I would then just code it as:



Code
perl -i -npe 's#RLM_LICENSE.*#RLM_LICENSE=$TEAM/licenses/abc.demo.lic#;' environment.properties



venhart
New User

Sep 15, 2011, 4:14 AM

Post #5 of 7 (1632 views)
Re: [rovf] Perl find and replace [In reply to] Can't Post

Hi,



Sorry i meant :

I need this to look like :

RLM_LICENSE=$TEAM_TOP/licenses/abc.demo.lic

and not like :

RLM_LICENSE=/team/dev6/data/REL1_TOP/licenses/abc.demo.lic

The Variable $TEAM_TOP is getting displayed in full as per above.


rovf
Veteran

Sep 15, 2011, 4:22 AM

Post #6 of 7 (1631 views)
Re: [venhart] Perl find and replace [In reply to] Can't Post

Again, then I simply would not have environment variable substitution taking place. In your case, it would be


Code
perl -i -npe 's#RLM_LICENSE.*#RLM_LICENSE=$TEAM_TOP/licenses/abc.demo.lic#;' environment.properties


instead of


Code
perl -i -npe "s#RLM_LICENSE.*#RLM_LICENSE=$TEAM_TOP/licenses/abc.demo.lic#;" environment.properties


So, the problem is with shell syntax, not with Perl code...


daptal
Novice

Oct 3, 2011, 6:11 PM

Post #7 of 7 (1460 views)
Re: [venhart] Perl find and replace [In reply to] Can't Post


Code
perl -i -npe "s#RLM_LICENSE.*#RLM_LICENSE=$TEAM_TOP/licenses/abc.demo.lic#;"


change the double quote to single quote as the interpolation is not required
ie


Code
perl -i -npe ' .... '


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives