LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Linux Answers > Programming
User Name
Password

Notices

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.

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 09:07 AM.

Main Menu
Advertisement

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