zoukankan      html  css  js  c++  java
  • Linux文件分割与合并

    1.分割命令 -split

    (1) 按行数分割:split -l 300 -d large_file.txt new_file_prefix --verbose
    -l 表示按行分割,300表示每个文件300行,-d表示使用数字后缀;加上--verbose,显示分割进度:

     1 [root@root test]$ ll
     2 total 6188
     3 -rw-rw-r-- 1 root root 6333541 Dec 19  2018 bigFile.dat
     4 [root@root test]$ split -l 20000 -d bigFile.dat bigFile.data_ --verbose
     5 creating file `bigFile.data_00'
     6 creating file `bigFile.data_01'
     7 creating file `bigFile.data_02'
     8 creating file `bigFile.data_03'
     9 [root@root test]$ ll
    10 total 12380
    11 -rw-rw-r-- 1 root root 6333541 Dec 19  2018 bigFile.dat
    12 -rw-rw-r-- 1 root root 1794909 Dec 10 06:32 bigFile.data_00
    13 -rw-rw-r-- 1 root root 1796880 Dec 10 06:32 bigFile.data_01
    14 -rw-rw-r-- 1 root root 1797622 Dec 10 06:32 bigFile.data_02
    15 -rw-rw-r-- 1 root root  944130 Dec 10 06:32 bigFile.data_03

    (2) 按字节大小分割 split -b 10m -d large_file.log new_file_prefix
    -b 表示按字节分割,10m 表示每个文件10m行,-d表示使用数字后缀;加上--verbose,显示分割进度:

    2.合并命令 -cat
    cat part_* > merge_file.txt

    1 [root@root test]$ cat bigFile.data_* > newBigFile.data
    2 [root@root test]$ ll
    3 total 18568
    4 -rw-rw-r-- 1 root root 6333541 Dec 19  2018 bigFile.dat
    5 -rw-rw-r-- 1 root root 1794909 Dec 10 06:32 bigFile.data_00
    6 -rw-rw-r-- 1 root root 1796880 Dec 10 06:32 bigFile.data_01
    7 -rw-rw-r-- 1 root root 1797622 Dec 10 06:32 bigFile.data_02
    8 -rw-rw-r-- 1 root root  944130 Dec 10 06:32 bigFile.data_03
    9 -rw-rw-r-- 1 root root 6333541 Dec 10 06:38 newBigFile.data

    3. 查看文件行数命令 -wc

    可以看到 合并后的文件行数和分割前的行数是一样的。

    1 [root@root test]$ wc bigFile.dat
    2   70509  438080 6333541 bigFile.dat
    3 [root@root test]$ wc bigFile.data_00
    4   20000  124171 1794909 bigFile.data_00
    5 [root@root test]$ wc bigFile.data_01
    6   20000  124272 1796880 bigFile.data_01
    7 [root@root test]$ wc newBigFile.data
    8   70509  438080 6333541 newBigFile.data

    参数文档

    https://www.cnblogs.com/bymo/p/7571320.html

  • 相关阅读:
    委托的说明和举例
    用C#编写获取远程IP,MAC的方法
    200个Gmail邀请,要的请留下邮箱地址
    .NET中各种数据库连接大全
    .net中何有效的使用Cache
    55种网页常用小技巧(javascript) (转)
    一个WEB项目安装包,自动配置数据库,config文件和虚拟目录。。(转)
    windows xp sp2后所有更新
    C#反射实例(转)
    可扩展的应用程序:新增功能时无须重新编译
  • 原文地址:https://www.cnblogs.com/veryvalley/p/10179770.html
Copyright © 2011-2022 走看看