Computing.Net > Forums > Unix > variable with path vs sed

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

variable with path vs sed

Reply to Message Icon

Name: tvc02
Date: June 9, 2008 at 02:03:36 Pacific
OS: w2k
CPU/Ram: n/a
Product: n/a
Comment:

OK, I'm trying to use SED to change the value of a line in a text, with a variable that contains a path, but it does not really work. Ex.

sed "/^VARIABLE1=/s/.*$/VARIABLE1=${VARIABLE1}/" $source_file > $target_file

This does not work if VARIABLE1 contains a regular path ( "/vol01/just/a/path" )

But, if you do this, it works

VARIABLE1=\\\/vol01\\\/just\\\/a\\\/path

But I need to redefine each variable first, which is difficult

How do I do that ?



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: June 9, 2008 at 07:55:41 Pacific
Reply:

show your contents of $source_file, and the part you need to change.


0

Response Number 2
Name: User123456789
Date: June 9, 2008 at 15:17:09 Pacific
Reply:

That line is:


VARIABLE1=/u01/just/a/wrong/path

Hi there.


0

Response Number 3
Name: ghostdog
Date: June 9, 2008 at 18:02:20 Pacific
Reply:

use awk


awk 'BEGIN{FS="="}
/VARIABLE1/{
$2="/new/path"
}1' file


0

Response Number 4
Name: tvc02
Date: June 10, 2008 at 05:29:05 Pacific
Reply:

That does not work


0

Response Number 5
Name: James Boothe
Date: June 10, 2008 at 15:19:12 Pacific
Reply:

Although a slash is the standard delimiter, the operands of the sed substitution command can be delimited by any character that you hope will not be in your data.

echo $VAR1
/vol01/just/a/path

cat source_file
VAR1=/u01/just/a/wrong/path

sed "/^VAR1=/s%.*%VAR1=${VAR1}%" source_file
VAR1=/vol01/just/a/path

sed "/^VAR1=/s#.*#VAR1=${VAR1}#" source_file
VAR1=/vol01/just/a/path

sed "/^VAR1=/s@.*@VAR1=${VAR1}@" source_file
VAR1=/vol01/just/a/path


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: variable with path vs sed

grep variable with blank space www.computing.net/answers/unix/grep-variable-with-blank-space/5469.html

Unix script in DOS w/ questions www.computing.net/answers/unix/unix-script-in-dos-w-questions/5848.html

sed problem with regular expression www.computing.net/answers/unix/sed-problem-with-regular-expression/6876.html