使用sed合并多个csv文件
我有 3 个 csv 文件想要合并。每个文件都有 3 个逗号分隔的列。
File 1 has columns a,b,c
File 2 has columns d,e,f
File 3 has columns g,h,i
我想将这 3 个文件合并为一个文件:
a,b,c,e,f,h
我可以使用 sed 来做到这一点吗?
我可以很容易地编写控制台应用程序或脚本,但我正在尝试获得一些 sed 技能并相信这应该是一个合适的任务?
I have 3 csv files I'd like to combine. Each file has 3 comma delimited columns.
File 1 has columns a,b,c
File 2 has columns d,e,f
File 3 has columns g,h,i
I'd like to combine the 3 files into a single file of:
a,b,c,e,f,h
Can I use sed to do that?
I could write a console app or script easily enough but I'm attempting to get some sed skills and believe this should be a suitable task?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Mat Mendel 的答案很好,除非您碰巧在 Windows 上使用 cygwin,在这种情况下,一些烦人的行尾字符怪癖就会发挥作用。这取决于 unix 命令实用程序,在本例中粘贴和剪切,使用 \n 作为行结束符,而不是 Windows 想要的 \r\n。
我无法快速弄清楚如何更改这些 utils 或 cygwin 的行尾字符,所以我很高兴能够使用 sed。
Mat Mendel's answer is good to go unless you happen to be on Windows using cygwin in which case some annoying end of line character quirks come into play. This is down to the unix command utilities, in this case paste and cut, using \n as the end of line character instead of the \r\n that Windows wants.
I couldn't qucikly work out how to change the end of line character for those utils or cygwin in general so I was happily able to make use of sed after all.
你可以这样做:
You can do:
或者只是剪切并粘贴:
Or just cut and paste: