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

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

问题描述

所以,我想创建一个脚本,需要3个参数:文件路径,确切的词来代替,并用什么来取代它。如何创建这样的事?

一般来说,我希望它有一个这样的API:

  script.batC:/myTextDoc.xml_WORD_TO_REPLACE_WordTo使用


解决方案

使用 FNR 实用的优于其他著名工具,因为它可以搜索和基于正则前pressions更换。也为UI爱好者可以配置UI选项,它可以生成可以然后在脚本中使用命令行字符串。很容易的,甚至是命令行stirng使用。

在此查找 HTTP://findandreplace.$c$cplex.com/

此外,它是没有任何dependicies单个exe文件,很容易使用。

例如:

  FNR --cl --dir--fileMask休眠。*--useRegEx
      --findfind_str_ex pression--replacereplace_string

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?

Generally I want it to have an API like this:

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

解决方案

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.

Find it here http://findandreplace.codeplex.com/

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

Example:

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

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

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