我遇到了MS LogParser v2.2的问题,似乎无法追踪“解决方案”。
我正在导入带有标题的UTF-16 TSV文件,并尝试将这些字段的子集导出到CSV文件,通常没有处理,但是有一个实例连接其中两个字段的中间空间(将名字和姓氏组合成一个全名。
问题是不仅所有字段都被双引号而不管oDQuotes
参数(我可以高兴地忽略),但是连接字段包含该双引号的结果。即给定两个字段Fred
和Bloggs
,连接字段的内容始终为
"Fred" "Bloggs"
而不是危害较小的
"Fred Bloggs"
甚至
Fred Bloggs
无论oDQuotes参数的值是多少(OFF,AUTO或ON)。这些双引号的存在不容忽视或容易丢弃。
我在批处理文件和Windows脚本中都试过这个:
e.g。批处理文件:
set lp=%ProgramFiles(x86)%\Log Parser 2.2\LogParser.exe
set fields=[Buyer E-mail Address]
set fields=%fields%, [Order ID]
set fields=%fields%, [Shipping Addr 1]
set fields=%fields%, [Shipping Addr 2]
set fields=%fields%, [Shipping City]
set fields=%fields%, [Shipping Postal Code]
set fields=%fields%, [Buyer First Name]
::set fields=%fields%, strcat([Buyer First Name], ' ', [Buyer Last Name]) --- does not work. :-(
set fields=%fields%, strcat([Buyer First Name], strcat(' ', [Buyer Last Name]))
set fields=%fields%, [Buyer Last Name]
set fields=%fields%, [Buyer Company]
set fields=%fields%, [Buyer Day Phone]
set sql=SELECT %fields% into chad_out.csv from %1
"%lp%" -q:ON -i:TSV -icodepage:-1 -nSep:1 -fixedSep:on -o:CSV -oDQuotes:OFF -fileMode:1 "%sql%"
或JScript:
function ProcessFile(filename) {
DebugEcho(50, "D&D File name is <" + filename + ">");
var lq = WScript.CreateObject("MSUtil.LogQuery");
var lqif = WScript.CreateObject("MSUtil.LogQuery.TSVInputFormat");
var lqof = WScript.CreateObject("MSUtil.LogQuery.CSVOutputFormat");
// check that we actually have the objects in question
if (lq && lqif && lqof) {
DebugEcho(100, "Everything ok");
} else {
DebugEcho(0, "Something bad with LogQuery objects - exiting");
WScript.Quit(1);
}
// see command line "> LogParser.exe -h -i:TSV" for details
lqif.codepage = -1; // this is for unicode
lqif.fixedSep = true; // seems to need this
lqif.nSep = 1; // seems to need this?
// see command line "> LogParser.exe -h -o:CSV" for details
lqof.oDQuotes = "OFF"; // OFF | AUTO | ON - doesn't make any difference!
lqof.fileMode = 1; // 0 - append, 1 - overwrite, 2 - ignore
var fields = [
"[Buyer E-mail Address]",
"[Order ID]",
"[Shipping Addr 1]",
"[Shipping Addr 2]",
"[Shipping City]",
"[Shipping Postal Code]",
"[Buyer First Name]",
"strcat([Buyer First Name], strcat(' ', [Buyer Last Name]))", //
"[Buyer Last Name]",
"[Buyer Company]",
"[Buyer Day Phone]"
];
var sql = [
"SELECT",
fields.join(", "),
"INTO", "chad_out.csv",
"FROM", filename
].join(" ");
DebugEcho(20, "query string:", sql);
lq.ExecuteBatch(sql, lqif, lqof);
}
我担心我实际上无法提供任何数据,因为它是保密的,但我希望我提供的插图已足够。
我还有其他选择(例如Python csv),但这至少需要将脚本打包成可执行文件(我不希望将Python安装为通常可用的软件)。
任何人都可以发现一些我明显错过控制引用行为的东西,或者这是否是一个强大工具的缺陷?谷歌搜索oDQuotes
似乎不是很有效率。
答案 0 :(得分:1)
这听起来像输入TSV文件中的引号,不是吗?如果是这种情况,则会使用字段值导入引号,您需要使用查询将其删除(使用SUBSTR(MyField, 1, -1)
)。
TSV不期望引用字段,因此不会删除它们。