请问是否有用于cmd.exe的sed类实用程序?

是否有用于cmd.exe的sed类实用程序?

我希望使用windows命令行以编程方式编辑文件内容(cmd.exe)。在*nix中SED完成这些任务。窗户里有等效的东西吗?


慕田峪4524236
浏览 532回答 3
3回答

动漫人物

今天Powershell救了我。为grep有:get-content somefile.txt | where { $_ -match "expression"}而为了sed有:get-content somefile.txt | %{$_ -replace "expression","replace"}有关更多细节,请参见Zain Naboulsis博客.

哔哔one

如果您不想安装任何东西(我假设您希望将脚本添加到将在其他机器上运行的某个解决方案/程序/etc中),您可以尝试创建一个VBS脚本(例如,replace.vbs):Const&nbsp;ForReading&nbsp;=&nbsp;1 Const&nbsp;ForWriting&nbsp;=&nbsp;2 strFileName&nbsp;=&nbsp;Wscript.Arguments(0) strOldText&nbsp;=&nbsp;Wscript.Arguments(1) strNewText&nbsp;=&nbsp;Wscript.Arguments(2) Set&nbsp;objFSO&nbsp;=&nbsp;CreateObject("Scripting.FileSystemObject") Set&nbsp;objFile&nbsp;=&nbsp;objFSO.OpenTextFile(strFileName,&nbsp;ForReading) strText&nbsp;=&nbsp;objFile.ReadAll objFile.Close strNewText&nbsp;=&nbsp;Replace(strText,&nbsp;strOldText,&nbsp;strNewText) Set&nbsp;objFile&nbsp;=&nbsp;objFSO.OpenTextFile(strFileName,&nbsp;ForWriting) objFile.Write&nbsp;strNewText objFile.Close你就像这样运行它:cscript&nbsp;replace.vbs&nbsp;"C:\One.txt"&nbsp;"Robert"&nbsp;"Rob"它类似于“Billweaver”提供的sed版本,但我认为这个版本在特殊(‘></)字符方面更友好。顺便说一句,这不是我写的,但我想不起来是从哪里来的。
打开App,查看更多内容
随时随地看视频慕课网APP