如何根据指定的行数拆分CSV文件? [英] How to split CSV files as per number of rows specified?

查看:773
本文介绍了如何根据指定的行数拆分CSV文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有CSV文件(约10,000行;每行有300列)存储在LINUX服务器上。
我想把这个CSV文件分成500个CSV文件,每个20个记录。 (每个都有与原始CSV中相同的CSV标题)

I've CSV file (around 10,000 rows ; each row having 300 columns) stored on LINUX server. I want to break this CSV file into 500 CSV files of 20 records each. (Each having same CSV header as present in original CSV)

有没有任何linux命令来帮助此转换?

Is there any linux command to help this conversion?

推荐答案

此工作原理:

tail -n +2 file.txt | split -l 20 - split_
for file in split_*
do
    head -n 1 file.txt > tmp_file
    cat $file >> tmp_file
    mv -f tmp_file $file
done

找到: http://edmondscommerce.github.io/linux/linux- split-file-eg-csv-and-keep-header-row.html

这篇关于如何根据指定的行数拆分CSV文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆