Artificial intelligent assistant

Remove absolute path from file with bash I have file "list.txt" containing absolute paths to other files /home/lin/bash/aaa /home/lin/bash/song.mp3 /home/lin/bash/doc.html /home/lin/bash/directory I want to assign path to variable path="/home/lin/bash/song.mp3" and then remove whole line with that path. I've tried sed -i '$path' list.txt and many other command with grep, echo but nothing works.

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

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 6e63244532741fadc365b6d2bff86163