linux如何将两个文件拆分,linux-如何将一个文本文件拆分为多个* .txt文件?

在我的Linux系统上(Red Hat Enterprise 6.9),split_files.txt.命令没有split_files.txt.或-l的命令行选项。

相反,我使用了这个:

split -d -l NUM_LINES really_big_file.txt split_files.txt.

其中split_files.txt.将数字后缀添加到split_files.txt.的末尾,而-l指定每个文件的行数。

例如,假设我有一个很大的文件,例如:

$ ls -laF

total 1391952

drwxr-xr-x 2 user.name group 40 Sep 14 15:43 ./

drwxr-xr-x 3 user.name group 4096 Sep 14 15:39 ../

-rw-r--r-- 1 user.name group 1425352817 Sep 14 14:01 really_big_file.txt

该文件有100,000行,我想将其拆分为最多30,000行的文件。 此命令将运行拆分,并在输出文件模式split_files.txt.的末尾附加一个整数。

$ split -d -l 30000 really_big_file.txt split_files.txt.

正确分割结果文件,每个文件最多30,000行。

$ ls -laF

total 2783904

drwxr-xr-x 2 user.name group 156 Sep 14 15:43 ./

drwxr-xr-x 3 user.name group 4096 Sep 14 15:39 ../

-rw-r--r-- 1 user.name group 1425352817 Sep 14 14:01 really_big_file.txt

-rw-r--r-- 1 user.name group 428604626 Sep 14 15:43 split_files.txt.00

-rw-r--r-- 1 user.name group 427152423 Sep 14 15:43 split_files.txt.01

-rw-r--r-- 1 user.name group 427141443 Sep 14 15:43 split_files.txt.02

-rw-r--r-- 1 user.name group 142454325 Sep 14 15:43 split_files.txt.03

$ wc -l *.txt*

100000 really_big_file.txt

30000 split_files.txt.00

30000 split_files.txt.01

30000 split_files.txt.02

10000 split_files.txt.03

200000 total

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值