Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.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
Linux 查找和替换多个文件上的文本_Linux_Bash_Ubuntu_Sed - Fatal编程技术网

Linux 查找和替换多个文件上的文本

Linux 查找和替换多个文件上的文本,linux,bash,ubuntu,sed,Linux,Bash,Ubuntu,Sed,我试图用https版本替换存在于许多html页面上的特定链接。我试过: grep -rl "http://server.iad.liveperson.net/hc/88956865/" ./ | xargs sed -i "s/http:\/\/server.iad.liveperson.net\/hc\/88956865\//https:\/\/server.iad.liveperson.net\/hc\/88956865\//g" 当我这样做的时候,即使是作为sudo,我也会 sed: c

我试图用https版本替换存在于许多html页面上的特定链接。我试过:

grep -rl "http://server.iad.liveperson.net/hc/88956865/" ./ | xargs sed -i "s/http:\/\/server.iad.liveperson.net\/hc\/88956865\//https:\/\/server.iad.liveperson.net\/hc\/88956865\//g"
当我这样做的时候,即使是作为
sudo
,我也会

sed: couldn't open temporary file ./customers/sedTR3AMu: Permission denied
customers
只是
/
中的第一个目录。因此,我认为它挂在第一个文件上,但不确定除此之外还有什么问题


感谢您的帮助

您应该尝试的第一件事是,对于您以前知道包含该字符串的文件,单独运行
sed
命令。我觉得
sed
命令可能在抱怨
/
字符

您应该尝试将
sed
命令更改为如下内容:

sed -i 's;http://server.iad.liveperson.net/hc/88956865/;https://server.iad.liveperson.net/hc/88956865/;g'

也就是说,使用
而不是
/
作为分隔符,因此您不必每次使用
\
时都转义
/

必须以root用户身份运行登录的命令,因为sed-i在/tmp中创建临时文件,并且需要写访问权限


谢谢:使用jim的语法和分号,效果很好。哦,我不必转义文字句点。

使用另一个分隔符
sed
<代码>sed's_http://server.iad.liveperson.net/hc/88956865/_https://server.iad.liveperson.net/hc/88956865/_g因为
sed
混淆了分隔符的起始和结束位置。文字句点前面应该有反斜杠。