how to use script sed with full path
I have a script like that
find `pwd` | sed -e "s\^.*root\/test/./" I get an error if I use a parameter replace the path like that my_path=root/test find `pwd` | sed -e "s\^.*$my_path/./" what should I do? |
my_path=root\/test
find `pwd` | sed -e 's/^.*'"$my_path"'/./' |
Quote:
error occur if I take out the single quotation mark like that, no error occur. find `pwd` | sed -e 's/^.*"$my_path"/./' however, the sed will not replace the pre-fix "root/test" to "." What is the different between single quotation mark and double quotation mark in sed? |
It's the shell, not sed, that is parsing the quotes. Double quotes allow variable interpolation, single quotes don't. There's a fair bit of info in the bash man page about it (I'm assuming your shell is bash).
You could also use a different separator for the substitute command in sed - then you shouldn't need to quote the variable. I'm not at a box I can test that on at the moment though. |
Code:
find `pwd` | awk '{gsub("root/test",".") }1' |
Quote:
how do define another separator for the command in sed? |
Hello gilead if it's ok i'll tell him for you. You can use the @ sign in sed if you like.
Code:
var="root/temp" |
Punctuation marks are popular. For an alternative, I go with colon ':', seems to stand out nicely when reading, esp if you are sed'ing dir paths.
|
Thank you everyone
The problem is solved. |
All times are GMT -5. The time now is 02:28 AM. |