CSV 文件处理 Windows 脚本,最好的工具,最简单的方法?
在 Windows 平台上,使用尽可能少的工具(更喜欢仅使用内置工具,例如 CMD,但我意识到可能需要 sed 之类的工具);我想创建一个执行如下的脚本。
它应该输入一个 csv 文件,从该文件中提取某些字段,然后输出一个新的且格式独特的输出 csv 文件,其中包含提取的字段。例如。
Input.csv
Cust#, CustFName, CustLName, Address, City, State, Zip, Order#, Qty, Part, Cost, Total,,,,
Output.csv
,,, Qty, City,,,, CustFName,,, Total,,, Zip,,,
csv 文件的记录数量会有所不同。有些将有 3 条记录,另一些将有 10,000 条记录。
On a Windows platform, using the fewest tools possible (prefer to use only built in tools such as CMD but I realize something like sed may be required); I would like create a script that will perform as follows.
It should input a csv file, extract certain fields from that file and then output a new and uniquely formatted output csv file that contains the extracted fields. For example.
Input.csv
Cust#, CustFName, CustLName, Address, City, State, Zip, Order#, Qty, Part, Cost, Total,,,,
Output.csv
,,, Qty, City,,,, CustFName,,, Total,,, Zip,,,
The csv files will vary the number of records. Some will have 3 records and others will have 10,000 records.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 VBscript,自 Win2K 以来几乎所有 Windows 系统都可以使用 VBscript。这是一个示例,假设您没有“引用”逗号。
从 cmd 行运行此命令,如“cscript yourscript.vbs”。对于“真实”的事情,您可能需要添加一些代码来处理不同数量的记录、逗号是引用记录的一部分的记录等等,但一般方法应该很清楚。
下面是 MS Win2K 脚本指南中的另一个示例:
http://technet.microsoft. com/en-us/library/ee176692.aspx
You can use VBscript, that should be available on almost all Windows systems since Win2K. Here is an example, assuming you don't have "quoted" commas.
Run this from the cmd line like "cscript yourscript.vbs". For the "real" thing, you will probably have to add some code to deal with different number of records, records where the comma is part of quoted records and so on, but the general approach should be clear.
Here is another example from the MS Win2K scripting guide:
http://technet.microsoft.com/en-us/library/ee176692.aspx