View the Most Wanted LQ Wiki articles.
Go Back > Linux Answers > Programming
User Name


By robiwan at 2010-03-22 05:13
The normal syntax for sed is:

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

app.log.path = REALLOGPATH/log.txt
and you want to replace REALLOGPATH by the content of $MY_LOG_PATH. The incorrect approach would be

# 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:

# sed -i "s;REALLOGPATH;$MY_LOG_PATH;" ./path/to/config_file
and you'll be fine.

by penguiniator on Mon, 2010-03-22 18:16
You can use nearly any character to delimit the regex and replacement text. A common replacement for / in sed expressions is #, especially when / appears in the pattern or replacement text.

by Don Johnston on Tue, 2012-11-20 09:53
I have a sed script which reads sed -e 's/@@/\xOA/g' file1 file2. It results in the file being displayed with the change. How can I have it transfer the file file with the replaced characters in place.

by sajjad008 on Tue, 2014-01-14 12:35
ok good


All times are GMT -5. The time now is 05:00 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration