Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.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_Ssh_Sed_Grep - Fatal编程技术网

Linux 在同一个直接和子文件夹中批量替换字符串

Linux 在同一个直接和子文件夹中批量替换字符串,linux,ssh,sed,grep,Linux,Ssh,Sed,Grep,我正在尝试使用以下方法替换字符串 grep -rl matchstring . | xargs sed -i 's/string1/string2/g' 我想实现的是,我现在得到了一个硬编码域名,比如 http://account.mysmallwebsite.com https://account.mysmallwebsite.com 因为这是非常不灵活的,我宁愿 <?php echo $domainName;?> 使用echo字符串,但如何通过putty shell ssh

我正在尝试使用以下方法替换字符串

grep -rl matchstring . | xargs sed -i 's/string1/string2/g'
我想实现的是,我现在得到了一个硬编码域名,比如

http://account.mysmallwebsite.com
https://account.mysmallwebsite.com
因为这是非常不灵活的,我宁愿

<?php echo $domainName;?>

使用echo字符串,但如何通过putty shell ssh的命令行实现它?您可以使用以下命令:

find . -name "*.php" -exec sed -r -i.bak 's#http(s?)://account.mysmallwebsite.com#<?php echo $domainName;?>#g' {} \;
请参见操作中的
sed
命令:

$ cat a
hello
http://account.mysmallwebsite.com
https://account.mysmallwebsite.com
httpss://account.mysmallwebsite.com
bye

$ sed -r 's#http(s?)://account.mysmallwebsite.com#<?php echo $domainName;?>#g' a
hello
<?php echo $domainName;?>
<?php echo $domainName;?>
httpss://account.mysmallwebsite.com
bye
$cat a
你好
http://account.mysmallwebsite.com
https://account.mysmallwebsite.com
httpss://account.mysmallwebsite.com
再见
$sed-r's#http(s?)://account.mysmallwebsite.com#g'a
你好
httpss://account.mysmallwebsite.com
再见

您可以使用以下功能:

find . -name "*.php" -exec sed -r -i.bak 's#http(s?)://account.mysmallwebsite.com#<?php echo $domainName;?>#g' {} \;
请参见操作中的
sed
命令:

$ cat a
hello
http://account.mysmallwebsite.com
https://account.mysmallwebsite.com
httpss://account.mysmallwebsite.com
bye

$ sed -r 's#http(s?)://account.mysmallwebsite.com#<?php echo $domainName;?>#g' a
hello
<?php echo $domainName;?>
<?php echo $domainName;?>
httpss://account.mysmallwebsite.com
bye
$cat a
你好
http://account.mysmallwebsite.com
https://account.mysmallwebsite.com
httpss://account.mysmallwebsite.com
再见
$sed-r's#http(s?)://account.mysmallwebsite.com#g'a
你好
httpss://account.mysmallwebsite.com
再见

您可以使用以下功能:

find . -name "*.php" -exec sed -r -i.bak 's#http(s?)://account.mysmallwebsite.com#<?php echo $domainName;?>#g' {} \;
请参见操作中的
sed
命令:

$ cat a
hello
http://account.mysmallwebsite.com
https://account.mysmallwebsite.com
httpss://account.mysmallwebsite.com
bye

$ sed -r 's#http(s?)://account.mysmallwebsite.com#<?php echo $domainName;?>#g' a
hello
<?php echo $domainName;?>
<?php echo $domainName;?>
httpss://account.mysmallwebsite.com
bye
$cat a
你好
http://account.mysmallwebsite.com
https://account.mysmallwebsite.com
httpss://account.mysmallwebsite.com
再见
$sed-r's#http(s?)://account.mysmallwebsite.com#g'a
你好
httpss://account.mysmallwebsite.com
再见

您可以使用以下功能:

find . -name "*.php" -exec sed -r -i.bak 's#http(s?)://account.mysmallwebsite.com#<?php echo $domainName;?>#g' {} \;
请参见操作中的
sed
命令:

$ cat a
hello
http://account.mysmallwebsite.com
https://account.mysmallwebsite.com
httpss://account.mysmallwebsite.com
bye

$ sed -r 's#http(s?)://account.mysmallwebsite.com#<?php echo $domainName;?>#g' a
hello
<?php echo $domainName;?>
<?php echo $domainName;?>
httpss://account.mysmallwebsite.com
bye
$cat a
你好
http://account.mysmallwebsite.com
https://account.mysmallwebsite.com
httpss://account.mysmallwebsite.com
再见
$sed-r's#http(s?)://account.mysmallwebsite.com#g'a
你好
httpss://account.mysmallwebsite.com
再见

Related:@fedorqui,如果我这么做的话-名称“*.txt”-exec sed-i s/Coke/Pepsi/g{}\,如何更改字符串以使其在http和https模式下工作,我对regex的使用非常糟糕抱歉询问相关:@fedorqui,如果我这样做的话-名称“*.txt”-exec sed-i s/Coke/Pepsi/g{}\,如何更改字符串以使其在http和https模式下工作,我对regex的使用非常糟糕抱歉询问相关:@fedorqui,如果我这样做的话-名称“*.txt”-exec sed-i s/Coke/Pepsi/g{}\,如何更改字符串以使其在http和https模式下工作,我对regex的使用非常糟糕抱歉询问相关:@fedorqui,如果我这样做的话-名称“*.txt”-exec sed-i s/Coke/Pepsi/g{}\,如何通过我的模式更改字符串以使其适用于http和https,我对正则表达式很不好对不起,我要问的是一种详尽的、非常明确的解释+1种详尽的、非常明确的解释+1种详尽的、非常明确的解释+1种详尽的、非常明确的解释+1种详尽的、非常明确的解释+1