如何将一个文本文件拆分为多个* .txt文件? [英] How to split one text file into multiple *.txt files?

查看:360
本文介绍了如何将一个文本文件拆分为多个* .txt文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件file.txt(12 MBs),其中包含:

I got a text file file.txt(12 MBs) containing:

something1
something2
something3
something4
(...)

有什么方法可以将file.txt分成12个* .txt文件,比如说file2.txtfile3.txtfile4.txt(...)吗?

Is there any way to split file.txt in to 12 *.txt files let say file2.txt, file3.txt, file4.txt (...) ?

推荐答案

您可以使用linux bash核心实用程序split

You can use the linux bash core utility split

split -b 1M -d  file.txt file 

请注意,MMB都可以,但是大小不同. MB为1000 * 1000,M为1024 ^ 2

Note that M or MB both are OK but size is different. MB is 1000 * 1000, M is 1024^2

如果要按行分隔,可以使用-l参数.

If you want to separate by lines you can use -l parameter.

更新

a=(`wc -l yourfile`) ; lines=`echo $(($a/12)) | bc -l` ; split -l $lines -d  file.txt file

Kirill 建议的另一种解决方案,您可以执行以下操作

Another solution as suggested by Kirill, you can do something like the following

split -n l/12 file.txt

请注意,不是l而不是onesplit -n有几个选项,例如Nk/Nl/k/Nr/Nr/k/N.

Note that is l not one, split -n has a few options, like N, k/N, l/k/N, r/N, r/k/N.

这篇关于如何将一个文本文件拆分为多个* .txt文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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