问题描述
我有一个文本文件file.txt
(12 MBs),其中包含:
I got a text file file.txt
(12 MBs) containing:
something1
something2
something3
something4
(...)
有什么方法可以将file.txt
分成12个* .txt文件,比如说file2.txt
,file3.txt
,file4.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
请注意,M
或MB
都可以,但是大小不同. 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
而不是one
,split -n
有几个选项,例如N
,k/N
,l/k/N
,r/N
,r/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文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!