在行末端替换文本字符串的脚本
如果
((Get-Content -path "C:\Users\User1\OUT\Summary.txt" -Raw) -replace '</ab></cb>','</x>') | Set-Content -Path "C:\Users\User1\OUT\Summary.txt"
可能
C:\Users\User1\File\Summary.txt
;&lt; b&gt; data
,同时以:&lt;/ab gt;&lt;/cb&gt;
来更改结局到:&lt;/x&gt;
它需要保存文件而不更改文件名。
例如,显示此数据的行:
<a><b>Data:</y> 12345678</ab></cb>
将更改为:
<a><b>Data:</y> 12345678</x>
上面的PowerShell脚本将找到&lt;/ab gt;&gt;/cb&gt;
的所有实例,并用&lt;/x&gt替换它;
,这不是我希望完成的。
I would like to modify this script if possible:
((Get-Content -path "C:\Users\User1\OUT\Summary.txt" -Raw) -replace '</ab></cb>','</x>') | Set-Content -Path "C:\Users\User1\OUT\Summary.txt"
I would like a script that will run with Windows OS to search through one file it finds at this path:
C:\Users\User1\File\Summary.txt
And within that file, when it finds data starting with: <a><b>Data
And at the same time ending with: </ab></cb>
It would need to change the ending to: </x>
And it would need to save the file without changing the name of the file.
For instance a line showing this data:
<a><b>Data:</y> 12345678</ab></cb>
Would be changed to:
<a><b>Data:</y> 12345678</x>
The PowerShell script above will find all instances of </ab></cb>
and replace it with </x>
, which is not what I am hoping to accomplish.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
get-content
处理文件行是行,只有在on
。这样的事情:&lt上拥有
; a&gt;&lt; b&gt;match
时,才能替换You can use
Get-Content
to process the file line be line and only do theReplace
when you have aMatch
on<a><b>
. Something like this: