【发布时间】:2017-10-03 21:40:42
【问题描述】:
我需要从某个文件中删除以下字符串:
Ba+/w+NWFlMa
我正在使用以下命令:
sed -i.bak '/Ba+/w+NWFlMa/d' /path/to/file
并得到以下错误:
sed: couldn't open file +NWFlMa/d: No such file or directory
我怎样才能解决这个问题并使'/'不分割字符串?
重要提示:此字符串是自动生成的,我通过 Java 代码调用命令,所以我不知道下次运行代码时该字符串会是什么删除它。
【问题讨论】:
-
您需要转义斜线:` sed -i .bak '/Ba+\/w+NWFlMa/d' /path/to/file`。斜线对于搜索命令来说显然是特殊的。