如何使用bat文件脚本替换文本文件中的文本? [英] How to replace text in text file using bat file script?

查看:182
本文介绍了如何使用bat文件脚本替换文本文件中的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想创建一个带有 3 个参数的脚本:文件路径、要替换的确切单词以及要替换的内容.如何创建这样的东西?

So I want to create a script that takes 3 arguments: path to file, exact word to replace, and with what to replace it. How to create such thing?

通常我希望它有这样的 API:

Generally I want it to have an API like this:

script.bat "C:/myTextDoc.xml" "_WORD_TO_REPLACE_" "WordTo Use"

推荐答案

Use fnr 实用程序比其他著名的实用程序更好,因为它可以基于正则表达式进行搜索和替换.同样对于 UI 爱好者,您可以在 UI 中配置选项,它可以生成命令行字符串,然后可以在您的脚本中使用.即使作为命令行搅拌也很容易使用.

Use fnr utility its better than other famous utility since it can search and replace based on regular expressions. Also for the UI lovers you can configure options in UI and it can generate command line string which can then be used in your script. Very easy to use even as command line stirng.

在此处查找 http://findandreplace.codeplex.com/

也是一个没有任何依赖的单一exe文件,使用起来非常方便.

Also it is single exe without any dependicies, so easy to use.

示例:

fnr --cl --dir "" --fileMask "hibernate.*" --useRegEx 
      --find "find_str_expression" --replace "replace_string"

这篇关于如何使用bat文件脚本替换文本文件中的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆