I'm having the following file:
- test.txt
which contains:
3;/var/tmp/test.mp4 3;/var/tmp/test2.mp4 1;/var/tmp/test3.mp4 I need to remove for example "3;/var/tmp/test2.mp4" using a variable.
string="3;/var/tmp/test2.mp4" sed -i '#$string#d' test.txt Does not throw any errors but I can't seem to get the line deleted... Any help would be appreciated.
Thanks!
1 Answer
You have to escape the first delimiter if different than / in the address.
Also if you use variables then you have to expose them to the shell (with double quotes to avoid problems with blanks).
sed -i "\#$string#d" test.txt or
sed -i '\#'"$string"'#d' test.txt 0