|
By robiwan at 2010-03-22 05:13
|
|
The normal syntax for sed is:
Code:
sed "s/FINDTHIS/REPLACEBYTHIS/"
but when you have a case where REPLACEBYTHIS contains the forward slash character, that syntax will fail.
For example, say that you have a shell variable MY_LOG_PATH=/var/log/here and there is a configuration file containing a setting like
Code:
app.log.path = REALLOGPATH/log.txt
and you want to replace REALLOGPATH by the content of $MY_LOG_PATH. The incorrect approach would be
Code:
# sed -i "s/REALLOGPATH/$MY_LOG_PATH/" ./path/to/config_file
Luckily, sed accepts other separators than the forward slash, so just change the line above and use a character normally
not found in paths, such as semicolon:
Code:
# sed -i "s;REALLOGPATH;$MY_LOG_PATH;" ./path/to/config_file
and you'll be fine.
|
|
|
|