Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.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
Windows Grep和SED不在PowerShell中工作_Windows_Powershell - Fatal编程技术网

Windows Grep和SED不在PowerShell中工作

Windows Grep和SED不在PowerShell中工作,windows,powershell,Windows,Powershell,我正在尝试替换1000多个文件中的url(使用PowerShell)。 也就是说,将托马斯公司测试网站:81/gt/se.ashx替换为乔治公司测试网站:91/gt/se.ashx 我能够使用以下命令在linux机器上执行它 grep -lr http:\/\/thomas\.corp\.test\.com:81\/gt\/se\.ashx . | xargs sed -i '' 's/http:\/\/thomas\.corp\.test\.com:81\/gt\/se\.ashx/htt

我正在尝试替换1000多个文件中的url(使用PowerShell)。 也就是说,将托马斯公司测试网站:81/gt/se.ashx替换为乔治公司测试网站:91/gt/se.ashx

我能够使用以下命令在linux机器上执行它

grep -lr http:\/\/thomas\.corp\.test\.com:81\/gt\/se\.ashx . |
  xargs sed -i '' 's/http:\/\/thomas\.corp\.test\.com:81\/gt\/se\.ashx/https:\/\/george\.corp\.test\.com:91\/gt\/se\.ashx/g' 

需要帮助找到与PowerShell等效的工具。

请尝试以下方法:

$odl="thomas.corp.test.com:81/gt/se.ashx"
$new="george.corp.test.com:91/gt/se.ashx"

select-string -Path "c:\temp\*.*" -Pattern $odl -SimpleMatch | %{$curpath=$_.path; (get-content $curpath -Raw) -replace $odl, $new | Out-File $curpath}
$old=“thomas.corp.test.com:81/gt/se.ashx”

$new=“george.corp.test.com:91/gt/se.ashx”


获取子项c:\somedir-recurse-include.| 选择-展开全名| 弗雷奇 { (获取内容$)-替换$旧,$新| 设置内容$


}

无论是谁,只要保持消极。。请注意,我们没有否决,但您如何希望在Windows操作系统上找到linux命令?如果你想在Windows上有一个bash环境,你可以在google上搜索gnuwin32(GNU工具的简单端口)、MinGW(靠近bash控制台)或Cygwin(几乎是Windows上的Linux仿真)。你当前的问题很糟糕,因为它没有显示任何研究。您应该阅读这里应该提出的问题。@SergeBallesta:“……您如何希望在Windows操作系统上找到linux命令?”又名“Windows上的Ubuntu”,是64位Windows 10的可选功能。get-childitem c:\somedir-recurse-include.|选择-展开全名| foreach{(获取内容$|)-替换$old、$new |设置内容$|}您能告诉我区别吗?使用您的方法有两个问题:getchilditem也获取目录,而不仅仅是文件。您的替换将应用于所有文件,不仅是包含旧strind->low performancesls内容的文件不会重复出现,而且只处理包含该模式的文件。