gpt4 book ai didi

javascript - 检查 CSV 文件内容并将其拆分为 2 个单独的文件

转载 作者:行者123 更新时间:2023-11-30 20:43:54 26 4
gpt4 key购买 nike

我有一个如下所示的 csv 文件:

Docushare Host
locale, created_at, version
en,Wed Feb 21 17:25:36 UTC 2018,07.00.00.C1.609

User
handle, client_data, docCountQuota
User-12,,-2

Document
handle,client_data,cfSpecialWords
Document-13,x,y
Document-14,z,a
Document-11,ab,cd

Collection
handle,client_data,routing_template
Collection-1,asdsad,asdad
Collection-2,xyz, abc
Collection-3,xada, adsad

是否有更快的方法来拆分此 CSV 并生成两个单独的文件:

 Document-13,x,y
Document-14, z, a
Document-15, ab, cd

 Collection-1,asdsad,asdad
Collection-2,xyz, abc
Collection-3,xada, adsad

这两个文件将用于 nodejs 应用程序,后者将再次解析它以创建包含所需字段的最终 CSV。

谢谢你们。

最佳答案

遵循简单的 awk 可能会对您有所帮助:

awk -F, '/^Document-/ && NF>1{print > "Document.csv";next} /^Collection/ && NF>1{print > "Collection.csv"}'   Input_file

现在也添加了一种非线性形式的解决方案:

awk -F, '
/^Document-/ && NF>1{
print > "Document.csv";
next
}
/^Collection/ && NF>1{
print > "Collection.csv"
}
' Input_file

作为输出,它将创建 2 个名为 Document.csvCollection.csv 的输出文件,其内容与您显示的相同。

关于javascript - 检查 CSV 文件内容并将其拆分为 2 个单独的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48944396/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com