Linux split分割xls或csv文件

Linux split分割xls或csv文件

  • 文件名:test.xls
split -a 2 -d -l 100 test.xls test

-a 2:后缀是2位
-d:后缀数字
-l 100 :每100行一个文件
test.xls:需要分割的文件名
test:分割后的文件前缀

批量修改文件后缀

for i in test*; do mv $i $i.xls; done

除了第一个文件有表头,其它分割出的文件均没有表头,需在文件第一行追加表头

// 先查看文件表头
head -1 test00

// 删除文件表头
sed -i '1d' test00

// 追加表头
sed -i '1i name\tusername\tpassword' test00.xls
或
// 批量追加表头
for i in * ; do sed -i '1i name\tusername\tpassword' $i; done

如果Windows打开xls文件打开中文乱码,需转译编码格式

iconv -futf8 -tgb2312 -otest_new.xls test.xls
// 或
iconv -futf8 -tgb18030 -otest_new.xls test.xls

Windows电脑打开csv或xls文件中文乱码问题(编码格式:UTF-8)

printf '\xEF\xBB\xBF' > test01_new.xls
cat test01.xls >> test01_new.xls

或

sed -i '1s/^/\xef\xbb\xbf/' test*
posted @ 2022-04-20 12:01  zongxiang  阅读(593)  评论(0编辑  收藏  举报