如何用\ n使用FART.exe替换\r\\\<br/>(文字) [英] How to replace \r\n (literal) with \n using FART.exe

查看:308
本文介绍了如何用\ n使用FART.exe替换\r\\\<br/>(文字)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server 2008中有一个用于批量加载的xml格式文件。我需要用<$替换 TERMINATOR =\r\\\
的实例C $ C> TERMINATOR = \\\
。我试图使用命令行工具 FART.exe 。无论我如何尝试,我似乎都无法使用实用程序来识别字符。



我试图以查找字符串和替换字符串的组合的方式传递:

  \r\\\
\ n
\r\\\
\\\

\r\\\
\\\

^ \r ^ \ n ^ \\\

TERMINATOR =\r\\\
TERMINATOR =\\\

TERMINATOR =^ \r ^ \TERMINATOR =^ \\\

以及许多其他组合。每一篇关于转义 DOS 命令的文章告诉我一些不同的东西,我已经尝试过所有这些都没有运气。真正奇怪的是,使用 \r\\\
\ n
不是做我想做的事(替换文字),但它不会取代在文件的每一行结尾处回车+换行字符。



我需要编辑的格式文件。我相信我用红色标出的那一行会产生一个问题:

解决方案使用 \\\
替换所有 \r\\\
文字
,只需使用:

  fart yourFile.xml \r\\\
\\\

仅替换大字符串 TERMINATOR =\r\\\
,然后使用:

  fart -C yourfile.xml TERMINATOR = \x22\\\r \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'我更喜欢使用 JREPL.BAT   - 它比FART更强大因为它可以使用正则表达式,另外它还有许多额外的高级功能。与FART相比,唯一的限制是它一次只能处理一个文件。



替换所有 \r\\\
文字与 \\\

  jrepl \ r \ n \\\
/ l / f yourFile.xml / o -

使用一个文字搜索字符串,引号转义为 \q 和反斜线为 \\

  jreplTERMINATOR = \q\\r\\\\
\qTERMINATOR = \q\\\ \\ n \ q/ x / l / f yourFile.xml / o -

或使用正则表达式:

  jrepl(TERMINATOR = \ q)\\r(?= \\\\\ \\ q)$ 1/ x / f yourFile.xml / o  -  


I have an xml format file for bulk loading in SQL Server 2008. I need to replace the instance of TERMINATOR="\r\n" with TERMINATOR="\n". I'm trying to use the command line utility FART.exe. No matter how I try, I cannot seem to get the utility to recognize the characters.

I have tried passing as combos of the find string and replace string:

\r\n \n
"\r\n" "\n"
""\r\n"" ""\n""
^\r^\n ^\n
TERMINATOR=""\r\n"" TERMINATOR=""\n""
TERMINATOR=""^\r^\n"" TERMINATOR=""^\n""

and many, many more combinations. Every article I look up about escaping DOS commands tells me something different and I've tried them all with no luck. The truly strange thing is that not only does using \r\n \n not do what I want it to do (replace the literals) but it does not replace the carriage return + line feed characters at the end of each line in the file.

The format file I need to edit. I believe the line I've underlined in red is causing a problem:

The command window output from calling Jrepl. It's obvious that the utility has a problem with the red-underlined line from the other screenshot:

解决方案

To replace all \r\n literals with \n, simply use:

fart yourFile.xml \r\n \n

To only replace within larger string TERMINATOR="\r\n", then use:

fart -C yourfile.xml TERMINATOR=\x22\\r\\n\x22 TERMINATOR=\x22\\n\x22

I prefer to use JREPL.BAT - It is much more powerful than FART in that it can use regular expressions, plus it has a number of additional advanced features. The only limitation relative to FART is it can only process one file at a time.

To replace all \r\n literals with \n:

jrepl \r\n \n /l /f yourFile.xml /o -

To be more specific using a literal search string with quote escaped as \q and backslash as \\:

jrepl "TERMINATOR=\q\\r\\n\q" "TERMINATOR=\q\\n\q" /x /l /f yourFile.xml /o -

or using a regular expression:

jrepl "(TERMINATOR=\q)\\r(?=\\n\q)" "$1" /x /f yourFile.xml /o -

这篇关于如何用\ n使用FART.exe替换\r\\\<br/>(文字)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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