LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   LinuxAnswers Discussion (http://www.linuxquestions.org/questions/linuxanswers-discussion-27/)
-   -   Shell variables in sed when using paths (http://www.linuxquestions.org/questions/linuxanswers-discussion-27/shell-variables-in-sed-when-using-paths-797113/)

robiwan 03-22-2010 03:09 PM

Shell variables in sed when using paths
 
A new la entry has been added:

Shell variables in sed when using paths

Quote:

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.

penguiniator 03-22-2010 06:16 PM

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.

Don Johnston 11-20-2012 08:53 AM

Sed lead character
 
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.

sajjad008 01-14-2014 11:35 AM

ok good


All times are GMT -5. The time now is 02:29 AM.