Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix 将文件路径变量插入Sed搜索/替换_Unix_Sed - Fatal编程技术网

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

Unix 将文件路径变量插入Sed搜索/替换,unix,sed,Unix,Sed,我正在尝试用sed搜索/替换,以便在Ubuntu操作系统上将文件路径插入字符串 要搜索/替换的行的示例: arc1.4x_os 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 `

我正在尝试用
sed
搜索/替换,以便在Ubuntu操作系统上将文件路径插入字符串

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

arc1.4x_os
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'
尝试的Sed代码:

arc1.4x_os
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'
预期输出:

arc1.4x_os
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'
终端错误消息:

arc1.4x_os
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'

下面的
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

我从来不知道可以使用管道分隔符,我一直使用正斜杠分隔符。