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
我从来不知道可以使用管道分隔符,我一直使用正斜杠分隔符。