2013-07-17 51 views
0

我试图用sed删除其中包含一个行的变量$filegrep使用sed来删除一个变量

filename=$(basename "$1") 
filegrep=$(grep "$filename" /home/$USER/Desktop/Trash/Index/Index.txt) 
filefir=$(dirname "filegrep") 

我试图用这个命令做到这一点:

sed -i '/$filegrep/d' /home/$USER/Desktop/Trash/Index/Index.txt 

然而,我收到错误

sed: no input files 
+0

欢迎堆栈溢出。请尽快阅读[关于]页面。请注意,花时间让拼写正确。很显然,'fielgrep','filegrep - $(...)','unput'是拼写错误;我怀疑'filefir'也是一个(更可能是'filedir');并且很可能该行应该是'filedir = $(dirname“$ filegrep”)'。请阅读如何创建SSCCE([简短,独立,正确的示例](http://sscce.org/))。 –

回答

1

字符串' -quote d瓦尔不扩大变量:在SED通话

[email protected]:~$ touch test.txt 
[email protected]:~$ X=test.txt 
[email protected]:~$ ls '$X' <---single-quoted 
ls: cannot access $X: No such file or directory 
[email protected]:~$ ls "$X" <---double-quoted 
test.txt 

更改你的报价来"

sed -i "/$filegrep/d" /home/$USER/Desktop/Trash/Index/Index.txt 
     ^--   ^--