将文件路径变量插入到Sed搜索/替换中

时间:2018-03-28 12:48:34

标签: unix sed

我正在尝试使用sed进行搜索/替换,以便将文件路径插入到Ubuntu OS上的字符串中。

要搜索/替换的行的示例:

arc1.4x_os

尝试了Sed代码:

blendpath="/home/weather/data/arc/"
sed "s/^arc1.4x_os/'\''open '${blendpath}'arc1.4x_os/g"

预期输出:

'open /home/weather/data/arc/arc1.4x_os

终端错误消息:

sed: -e expression #1, char 20: unknown option to `s'

1 个答案:

答案 0 :(得分:2)

关注sed可能对您有帮助。

echo "arc1.4x_os" | sed "s|arc1.4x_os|'open /home/weather/data/arc/&|"

我使用上面的echo来打印变量,例如你也可以使用sed来表示输入文件。

sed "s|arc1.4x_os|'open /home/weather/data/arc/&|"  Input_file