I'm trying to modifying a path stored in a variable ($var) through sed. In truth, I need to replace $(dirname "$var") for reasons related to the purpose of my script.
An example of var is var=/dir/dir xyz/file.txt, while filename contains several paths to be substituted which could be in any position (once near the middle of the line, another at the beginning, etc). Below I try to give an example of filename:
dog foo/bar /dir/dir xyz/file.txt
a b c d /dir/dir xyz/file.txt x y z
/dir/dir xyz/file.txt 1234
{[(/dir/dir xyz/file.txt
What I want is
dog foo/bar .
a b c d . x y z
. 1234
{[(.
I tried the following
sed "s|"$(dirname "$var")"|.|g" "$filename"
obtaining sed: -e expression #1, char 31: unterminated `s' command
Could you help me? Of course, you could suggest another way besides sed.