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

  • 相关阅读:
    js对象的sessionStorage,判断对象相等,判断是否包含某属性
    vant-ui的van-area使用
    JavaScript返回格式化的时间字符串
    vant-ui的van-uploader上传图片
    移动端vue页面禁止移动/滚动
    vue项目中的跨域源请求拦截问题CORS头缺少'Access-Control-Allow-Origin'
    项目开发过程中踩坑和填坑
    周报
    构建一个最简单的react程序
    Socket实现简易“多人聊天室”
  • 原文地址:https://www.cnblogs.com/veryvalley/p/10179770.html
Copyright © 2011-2022 走看看