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

  • 相关阅读:
    MySql中启用InnoDB数据引擎的方法
    云说的到底对不对,京东到底行不行?
    hibernate HQL查询的参数绑定
    MySQL到底能支持多大的数据量?
    C# RSA和Java RSA互通
    Log4j 2使用教程
    Log4j.properties配置详解
    JMX 基础Demo
    iBatis缓存实现源码分析-FIFO,LUR实现方法
    SqlMapClient 创建过程之SqlMapConfigParser源码走读
  • 原文地址:https://www.cnblogs.com/veryvalley/p/10179770.html
Copyright © 2011-2022 走看看