我想使用Windows命令行( cmd.exe )以编程方式编辑文件内容。在* nix中,有 sed 用于执行此任务。
- Cygwin 的工作原理
- UnxUtils 更加纤薄。
- GnuWin32 是另一个工作的港口。
- 另一个选择是AT& T Research的 UWIN系统。
- MSGY 是MinGw的另一个选择。
- Windows Services for UNIX 是最原生的选项,但它已安装默认情况下在Windows Server计算机上;它有 sed , grep 等开箱即可。
- Cygwin works but is gigantic.
- UnxUtils is much slimmer.
- GnuWin32 is another port that works.
- Another alternative is AT&T Research's UWIN system.
- MSYS from MinGw is yet another option.
- Windows Services for UNIX is a most "native" option, but it's installed by default on on Windows Server machines; it has sed, grep etc. out of the box, though.
如果你不想安装任何东西,你的系统不是Windows Server系统,那么你可以使用脚本语言(VBScript eg ) 为了那个原因。下面是一个粗暴,off-the-cuff刺。你的命令行看起来像
cscript // NoLogo sed.vbs s /(oldpat)/(newpat)/& inpfile.txt> outfile.txt其中oldpat和newpat Microsoft vbscript regex模式。显然,我只实现了replace命令,并假定了一些东西,但你可以更聪明,更容易理解 sed 命令行。
Dim pat,patparts,rxp,inp pat = WScript.Arguments(0) patparts = Split /)设置rxp = new RegExp rxp.Global = True rxp.Multiline = False rxp.Pattern = patparts(1) WScript.StdIn.AtEndOfStream inp = WScript.StdIn.ReadLine() WScript.Echo rxp.Replace(inp,patparts(2)) Loop
I want to programmatically edit file content using windows command line (cmd.exe). In *nix there is sed for this tasks. Is there any usefull equivalent in windows?
Edit: I am looking for native command line solution.
解决方案sed (and its ilk) are contained within several packages of Unix commands.
If you don't want to install anything and your system ain't a Windows Server one, then you could use a scripting language (VBScript e.g.) for that. Below is a gross, off-the-cuff stab at it. Your command line would look like
cscript //NoLogo sed.vbs s/(oldpat)/(newpat)/ < inpfile.txt > outfile.txtwhere oldpat and newpat are Microsoft vbscript regex patterns. Obviously I've only implemented the substitute command and assumed some things, but you could flesh it out to be smarter and understand more of the sed command-line.
Dim pat, patparts, rxp, inp pat = WScript.Arguments(0) patparts = Split(pat,"/") Set rxp = new RegExp rxp.Global = True rxp.Multiline = False rxp.Pattern = patparts(1) Do While Not WScript.StdIn.AtEndOfStream inp = WScript.StdIn.ReadLine() WScript.Echo rxp.Replace(inp, patparts(2)) Loop
更多推荐
是否有任何sed类似于cmd.exe的实用程序
发布评论