zoukankan      html  css  js  c++  java
  • 【Linux常见命令】split命令

    split - split a file into pieces

    按照指定的行数或大小分割文件

    语法: split [OPTION]... [INPUT [PREFIX]]

    •  Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; 指定前缀后面跟的分割的文件的序列为aa,ab,ac,...
    • default size is 1000 lines, 默认的分割大小为1000行
    • and default PREFIX is 'x'.   如不指定前缀,默认的前缀为x
    • With no INPUT, or when INPUT is -, read standard input.  如果文件没有输入,或者输入是-,则可以读取标准输入。

    示例:

     1 # 数据准备,将/etc/passwd的数据导入到split_test.txt
     2 # 查看split_test.txt的内容
     3 [root@oldboy oldboy]# head -1 split_test.txt
     4 root:x:0:0:root:/root:/bin/bash
     5 [root@oldboy oldboy]# wc -l split_test.txt 
     6 72 split_test.txt
     7 
     8 # 将文件按行分文件,按30行作为分割条件
     9 # 在不指定前缀的情况下,默认的输出的文件的文件名前缀为"x"
    10 [root@oldboy oldboy]# split -l 30 split_test.txt  
    11 [root@oldboy oldboy]# ls
    12 date_str.txt  split_test.txt  test.sh  xaa  xab  xac
    13 
    14 # 指定输出文件的前缀
    15 [root@oldboy oldboy]# split -l 40 split_test.txt new_prefix_ 
    16 [root@oldboy oldboy]# ls new*
    17 new_prefix_aa  new_prefix_ab

    参数:

    • -a, --suffix-length=N
      • use suffixes of length N (default 2)
      • 指定生成文件后缀长度
      • 1 [root@oldboy oldboy]# split -l 40 -a 4 split_test.txt arg_a_test_ 
        2 [root@oldboy oldboy]# ls arg*
        3 arg_a_test_aaaa  arg_a_test_aaab
    • -b, --bytes=SIZE
      • put SIZE bytes per output file
      • 指定字节大小分割文件
      •  1 # 按1k切割文件
         2 [root@oldboy oldboy]# split -b 1k split_test.txt      
         3 [root@oldboy oldboy]# ls x*
         4 xaa  xab  xac
         5 
         6 # 查看输出的文件的行数
         7 [root@oldboy oldboy]# wc -l x*
         8   23 xaa
         9   25 xab
        10   24 xac
        11   72 total
        12 
        13 # 查看文件的大小
        14 [root@oldboy oldboy]# ll -h x*
        15 -rw-r--r-- 1 root root 1.0K Nov  5 23:08 xaa
        16 -rw-r--r-- 1 root root 1.0K Nov  5 23:08 xab
        17 -rw-r--r-- 1 root root 1010 Nov  5 23:08 xac
    • -C, --line-bytes=SIZE
      • put at most SIZE bytes of lines per output file 
      • 与参数"-b"相似,但是在切割时将尽量维持每行的完整性
    • -d, --numeric-suffixes
      • use numeric suffixes instead of alphabetic
      • 使用数字后缀
      • 1 [root@oldboy oldboy]# split -l 40 -d split_test.txt arg_d_test_
        2 [root@oldboy oldboy]# ls arg_d_test_*
        3 arg_d_test_00  arg_d_test_01
    • -l, --lines=NUMBER
      • put NUMBER lines per output file
      • 按行分割文件
  • 相关阅读:
    django基础入门(3)django中模板
    ms sql 索引(一)
    Ruby入门(3)——方法、代码段
    Ruby入门(2)——基本流程控制
    Ruby入门(4)——类
    Ruby入门(1)——数据类型
    django基础入门(1)django基本配置
    四则运算加强版
    结对 四则运算
    chrome设置以及hosts备份
  • 原文地址:https://www.cnblogs.com/zoe233/p/11802273.html
Copyright © 2011-2022 走看看