猿问
是否有用于cmd.exe的sed类实用程序?
是否有用于cmd.exe的sed类实用程序?
我希望使用windows命令行以编程方式编辑文件内容(
cmd.exe
)。在*nix中
SED
完成这些任务。窗户里有等效的东西吗?
浏览 986
回答 3
3回答
今天Powershell救了我。为grep有:get-content somefile.txt | where { $_ -match "expression"}而为了sed有:get-content somefile.txt | %{$_ -replace "expression","replace"}
0
0
0
如果您不想安装任何东西(我假设您希望将脚本添加到将在其他机器上运行的某个解决方案/程序/etc中),您可以尝试创建一个VBS脚本(例如,replace.vbs):Const ForReading = 1 Const ForWriting = 2 strFileName = Wscript.Arguments(0) strOldText = Wscript.Arguments(1) strNewText = Wscript.Arguments(2) Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strFileName, ForReading) strText = objFile.ReadAll objFile.Close strNewText = Replace(strText, strOldText, strNewText) Set objFile = objFSO.OpenTextFile(strFileName, ForWriting) objFile.Write strNewText objFile.Close你就像这样运行它:cscript replace.vbs "C:\One.txt" "Robert" "Rob"它类似于“Billweaver”提供的sed版本,但我认为这个版本在特殊(‘></)字符方面更友好。顺便说一句,这不是我写的,但我想不起来是从哪里来的。
0
0
0
随时随地看视频
慕课网APP
相关分类
操作系统
windows桌面的系统图标是程序吗?和普通程序有什么不同?
1 回答
关于操作系统安装不上 的问题?
3 回答
我要回答