是否有任何sed类似于cmd.exe的实用程序

编程入门 行业动态 更新时间:2024-10-24 18:28:30
本文介绍了是否有任何sed类似于cmd.exe的实用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用Windows命令行( cmd.exe )以编程方式编辑文件内容。在* nix中,有 sed 用于执行此任务。

  • Cygwin 的工作原理
  • UnxUtils 更加纤薄。
  • GnuWin32 是另一个工作的港口。
  • 另一个选择是AT& T Research的 UWIN系统。
  • MSGY 是MinGw的另一个选择。
  • Windows Services for UNIX 是最原生的选项,但它已安装默认情况下在Windows Server计算机上;它有 sed , grep 等开箱即可。
    • 如果你不想安装任何东西,你的系统不是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.

      • 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.

      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.txt

      where 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的实用程序

本文发布于:2023-07-05 07:52:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1034871.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类似于   实用程序   有任何   sed   cmd

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!