作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个如下所示的 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.csv
和 Collection.csv
的输出文件,其内容与您显示的相同。
关于javascript - 检查 CSV 文件内容并将其拆分为 2 个单独的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48944396/
我是一名优秀的程序员,十分优秀!