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

    原文作者:weixin_39600837
    原文地址: https://blog.csdn.net/weixin_39600837/article/details/116550131
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞