且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何用bat文件脚本来替换文本文件中的文本?

更新时间:2023-02-23 16:54:43

使用 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"