Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 ?

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/pathcat source_file
VAR1=/u01/just/a/wrong/pathsed "/^VAR1=/s%.*%VAR1=${VAR1}%" source_file
VAR1=/vol01/just/a/pathsed "/^VAR1=/s#.*#VAR1=${VAR1}#" source_file
VAR1=/vol01/just/a/pathsed "/^VAR1=/s@.*@VAR1=${VAR1}@" source_file
VAR1=/vol01/just/a/path

![]() |
![]() |
![]() |

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