There are two problems with your solution. First since you're using single quotes for '$path'
this expression is treated literally, and not like the variable $path
. In order to solve this use double quotes "$path"
. But then you will face the second problem: you want to use slash /
as a special sed
-symbol and at the same time this symbol is present in paths, which will confuse sed
. Therefore you have to use some other symbol instead of slash, for example, use comma
$ sed -i "s,${path},," list.txt $ cat list.txt /home/lin/bash/aaa /home/lin/bash/doc.html /home/lin/bash/directory
There is another beautiful approach, suggested by Tim Kennedy (see explanation of how it works in the discussion below), which does not leave the blank line
$ sed -i "\,${path},d" list.txt $ cat list.txt /home/lin/bash/aaa /home/lin/bash/doc.html /home/lin/bash/directory