Help with sed syntax and single quotes
Hey all,
I've searched a ton on this, but couldn't find what I was hoping to find. I want to use sed to replace some text in a config file. I've used it successfully before in situations without single quotes, but this time single quotes are part of the string that I want to insert into the file. Here's the command: Code:
sed -i 's?library_dirs = [?library_dirs = ['$PATH_TO_FTDI', ?g' ./setup.py I know the solution requires escaping, and I get that when it comes to, say, directory names with spaces in them (e.g. My\ Whacky\ Folder), but I'm not sure how to do it here. Thanks, Gabe |
Hi,
instead of escaping the single quotes in your replacement text you can switch to using double quotes in the sed command. You will however need to escape the $ and [. Eg Code:
sed -i "s?library_dirs = \[?library_dirs = \['\$PATH_TO_FTDI', ?g" ./setup.py Evo2. |
That worked almost perfectly, thanks!
The only thing it didn't do is replace $PATH_TO_FTDI with what is actually in that environment variable. PATH_TO_FTDI=/usr/local/include/libftdi1/, and it's that actual path that I want to show up in the setup.py file. Unless python will see that environment variable as-is, which I guess would be ok too. |
Hi,
Quote:
Code:
sed -i "s?library_dirs = \[?library_dirs = \['$PATH_TO_FTDI', ?g" ./setup.py Quote:
Code:
import os Evo2. |
Awesome, thanks!
|
Remember to mark as SOLVED once you have a solution.
|
All times are GMT -5. The time now is 05:07 AM. |