Perl command to replace path part of variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl command to replace path part of variable
# 1  
Old 03-25-2011
Perl command to replace path part of variable

I'm trying to replace path which is part of variable inside script file:

FROM:
Code:
ABC_HOME=$ABC_ROOT/abc/1.0

TO:
Code:
ABC_HOME=$ABC_ROOT/abc/1.5

I'm using this:
Code:
perl -pi -e 's\ABC_HOME=$ABC_ROOT/abc/1.0\ABC_HOME=$ABC_ROOT/abc/1.5\g' /apps/scripts/test.sh

This command is not working because "=" sign. Is there a way to modify this command to make it work?

Thanks,
djanu

Last edited by Franklin52; 04-08-2011 at 03:22 AM.. Reason: Please use code tags
# 2  
Old 03-25-2011
Problem is not in '=', its in the dollar sign. You need to escape the dollar (and use other delimiter for s//g):

Code:
$ cat test 
ABC_HOME=$ABC_ROOT/abc/1.0
$ cat test |  perl -pe 's+ABC_HOME=\$ABC_ROOT/abc/1.0+ABC_HOME=\$ABC_ROOT/abc/1.5+g' 
ABC_HOME=$ABC_ROOT/abc/1.5

# 3  
Old 04-07-2011
Thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

String variable as part of expression in find command

Hi, I am new in scripting, and I am currently working on a script that will look for other files in a certain directory and exclude some file type. this works fine:Find_File2Exclude=`find ${paths} -maxdepth 1 -type f \( ! -iname '*.out' ! -iname '*.auc' ! -iname '*.cps' ! -iname '*.log' ! -iname... (4 Replies)
Discussion started by: kedd05
4 Replies

2. UNIX for Advanced & Expert Users

How can i assign directory path to a variable in perl?

Hai how can I assign directory path to a variable in perl Thanks&Regards kiran (3 Replies)
Discussion started by: kiran425
3 Replies

3. UNIX for Dummies Questions & Answers

How can i assign directory path to a variable in perl?

Hai how can I assign directory path to a variable in perl Thanks&Regards kiran (2 Replies)
Discussion started by: kiran425
2 Replies

4. Shell Programming and Scripting

use some part of variable value to replace ../../ values in a file

hi, i have variable value as follows val="/dir1/dir2/dir3/dir4/dir5/dir6/file1" it is pointing to some file location. and i have another file as ../../dir4/file3 ../../dir4/dir5/file4 ../../dir7/file5 i want the output as /dir1/dir2/dir3/dir4/file3 (7 Replies)
Discussion started by: snreddy_gopu
7 Replies

5. Shell Programming and Scripting

How to search/replace a directory path in a file using perl

Hello All, Here is what I am trying to do and maybe you guys can point me in the right direction. I have a file that contains the following string(s): WARNING: </d1/test/program1> did not find item1 WARNING: </d1/test/program1> item1 does not exist WARNING: </d1/test/program2> item1 failed... (1 Reply)
Discussion started by: maxshop
1 Replies

6. Shell Programming and Scripting

Find and replace string from file which contains variable and path - SH

e.g. /home/$USER/.config replace it with "" (empty) Is this possible? I think you should play a bit with sharps ## and sed:b: (2 Replies)
Discussion started by: hakermania
2 Replies

7. Shell Programming and Scripting

How to find the count and replace the particular part of string in perl?

Hi, I am taking the current time using localtime function in perl. For example if the time is: #Using localtime $time = "12:3:10"; I have to replace the value 3 (03) i.e second position to be 03. The output should be: 12:03:10 But if the other string for example: $str:... (1 Reply)
Discussion started by: vanitham
1 Replies

8. Shell Programming and Scripting

Set specific part in command output into variable

I am trying unsuccessfully to set into a variable a specific part of command output: The command output will be as: line 1: <varied> line 2: 2 options: option 1: Set view: ** NONE ** or option 2: Set view: <different_name_of_views_always_without_spaces> and I would like to get into... (7 Replies)
Discussion started by: orit
7 Replies

9. Shell Programming and Scripting

direction symbol in a variable as part of the command

Hi, How can I get this to work? #!/bin/ksh if ; then direction=">>" else direction=">" fi cat some_file_name $direction temp.txt exit This shell script is not happy with using "$direction" opposed to ">" or ">>". Thanks. (5 Replies)
Discussion started by: peterloo
5 Replies

10. UNIX for Dummies Questions & Answers

display full unix path as part of the command line

Hi all, Does anyone know how to ammend the .cshrc file in $HOME for your session to display the path as part of the command line? So that I dont need to keep on typing pwd to see where I am? thanks Ocelot (3 Replies)
Discussion started by: ocelot
3 Replies
Login or Register to Ask a Question