zoukankan      html  css  js  c++  java
  • linux 命令 — split

    split

    按照数据大小和行数来分割文件

    指定分割文件后缀

    split -b 10k data.file
    按照每个文件10k分割文件(默认使用字母作为后缀)

    split -b 10k data.file -d -a 4
    使用数字作为分割文件的后缀,后缀长度为4

    指定前缀

    split [command_args] prefix

    split -b 10k data.file -d -a 4 split_file
    将split_file作为分割文件名称的前缀

    按行分割文件

    split -l 10 data.file
    每10行分割为一个文件

    按照文件自身特点分割csplit

    有文本文件如下:

    SERVER-1
    [connection] 192.168.0.1 success
    [connection] 192.168.0.1 success
    [connection] 192.168.0.1 success
    SERVER-2
    [connection] 192.168.0.1 success
    [connection] 192.168.0.1 success
    [connection] 192.168.0.1 success
    SERVER-1
    [connection] 192.168.0.1 success
    [connection] 192.168.0.1 success
    [connection] 192.168.0.1 success
    

    按照服务器分割文件

    csplit server.log /SERVER/ -n -s {*} -f server -b "%02d.log"; rm server00.log
    /SERVER/: 用来匹配某一行
    /[REGEX]/: 表示文本样式。包括从当前行直到(但不包括)包含"SERVER"的匹配行
    {星号}: 表示匹配重复执行分割,直到文件末尾为止,可以用{整数}指定分割执行次数
    -s: 是命令进入静默模式,不打印其他信息
    -n: 指定分割后的文件名后缀数字个数
    -f: 指定分割后文件名的前缀
    -b: 指定后缀的格式。类似c语言的printf参数格式,这里文件名=前缀+后缀=server + %02d.log
    rm server00.log: 因为文件中并没有SERVER-00,所以删除该文件

  • 相关阅读:
    English,The Da Vinci Code, Chapter 23
    python,meatobject
    English,The Da Vinci Code, Chapter 22
    English,The Da Vinci Code, Chapter 21
    English,The Da Vinci Code, Chapter 20
    English,The Da Vinci Code, Chapter 19
    python,xml,ELement Tree
    English,The Da Vinci Code, Chapter 18
    English,The Da Vinci Code, Chapter 17
    English,The Da Vinci Code, Chapter 16
  • 原文地址:https://www.cnblogs.com/sunshine-2015/p/7096863.html
Copyright © 2011-2022 走看看