批处理 - 字符串替换有特殊字符 [英] Batch - String replacement with special characters

查看:964
本文介绍了批处理 - 字符串替换有特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用批处理文件来替换在一个文件中的字符串。

该字符串是:

 )(

和我想通过替换它:

 ),

我发现了几个帖子,像这样的:<一href=\"http://stackoverflow.com/questions/5273937\">\"how-to-replace-substrings-in-windows-batch-file\"但示例使用虚拟字符串没有特殊字符。

感谢您!

修改

上下文:我用 mysqldump的来抽取一个数据库,我想插入命令的每一行以获取更多的可视性一个新行。

我不希望使用 - 延长插入= FALSE ,因为它会减慢备份重返

EDIT2

例如:

  INSERT INTO`dummytable`(`dummycolumn`)VALUES(1),(2),(3);

我希望它是:

  INSERT INTO`dummytable`(`dummycolumn`)VALUES(1)
(2),
(3);


解决方案

看看的 replacer.bat

 通话replacer.batE?C:\\ content.txt\\ u0022),(\\ u0022\\ u0022),\\ u000a(\\ u0022

修改不带引号:

 通话replacer.batE?C:\\ content.txt),(),\\ u000a(

windows风格

 通话replacer.batE?C:\\ content.txt),(),\\ u000D \\ u000a(

您还可以查看 FindRepl 和<一个HREF =htt​​p://www.dostips.com/forum/viewtopic.php?f=3&t=6044相对=nofollow> JRepl 这是更复杂的工具

I would like to replace a string in a file using a batch file.

The string is:

),(

And I want to replace it by:

),
(

I found several posts, like this one : "how-to-replace-substrings-in-windows-batch-file" but the example uses a dummy string with no special characters.

Thank you !

EDIT

Context: I use mysqldump to extract a database and I would like every line of the insert command to be on a new line for more visibility.

I don't want to use --extended-insert=false because it slows down reinsertion of the backup.

EDIT2

Example:

INSERT INTO `dummytable` (`dummycolumn`) VALUES (1),(2),(3);

I want it to be:

INSERT INTO `dummytable` (`dummycolumn`) VALUES (1),
(2),
(3);

解决方案

Take a look at replacer.bat

call replacer.bat "e?C:\content.txt" "\u0022),(\u0022" "\u0022),\u000a(\u0022"

Edit without the quotes:

call replacer.bat "e?C:\content.txt" "),(" "),\u000a("

windows style

call replacer.bat "e?C:\content.txt" "),(" "),\u000D\u000a("

you can check also FindRepl and JRepl which are more sophisticated tools

这篇关于批处理 - 字符串替换有特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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