Environment:Windows 10 pro 20H2,PowerShell 5.1.19041.1237
在.txt文件中,下面的PowerShell代码不会用" "替换换行符。问题:我在这里可能缺少了什么,我们如何使它工作?
C:\MyFolder\Test.txt文件:
This is first line.
This is second line.
This is third line.
This is fourth line.
将换行符替换为“”字符后,需要输出
This is first line. This is second line. This is
对使用分组和拆分操作是否有一些警告?
在perl中:
print join("|",split(m/(A|AND)/,"foo A bar"))."\n";
预期:
foo | bar
输出:
foo |A| bar
Powershell的相同预期/输出:
([regex]::Split("foo A bar","(A|AND)"))-join"|"
似乎在使用分组时出现了问题--没有括号,一切都很好:
([regex]::Split("foo A bar","A|B"
我试图通过cmd运行一个带有多个字符串参数的powershell命令。
上下文是,我想使用Compress-Archive函数/脚本中的Matlab。而Matlab只能访问cmd。
但是,当在cmd中调用powershell.exe时,我找不到一种方法来保留字符串参数中的连续空格。
C:\Users\Artus>powershell.exe echo 'a c'
a c
C:\Users\Artus>powershell.exe echo \"a c\"
a c
C:\Users\Artus>powershell.exe echo
我的目标是编写一个批处理脚本,该脚本将从特定的缓存服务器中删除所有缓存名称。
我在下面编写的代码出错了,因为它不能执行AppFabric PowerShell命令。它返回"Remove-Cache -CacheName blahblah" is not a recognized as an internal or external command。
我想我需要弄清楚--我需要你们的帮助--是如何使用shell脚本FOR /F命令,但仍然能够执行AppFabric PowerShell命令。
我试着加了一句:
powershell.exe -noexit -command