Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize File Segmentation and merging under Linux

Shulou Source: shulou.com Published: 2022-06-01 17:53:31 09月14日 Update

This article mainly introduces how to achieve file segmentation and merging under Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

File segmentation under linux can be achieved through the split command, you can split a large file into multiple files of a specified size, and the split speed is very fast, you can specify two modes: split by the number of lines and Ann size. File merging under Linux can be achieved through the cat command, which is very simple.

File Segmentation with split under Linux

Take a look at the help documentation first.

Usage: split [OPTION]... [INPUT [PREFIX]] Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab,...; defaultsize is 1000 lines, and default PREFIX is `xrabbit. With no INPUT, or when INPUTis -, read standard input.Mandatory arguments to long options are mandatory for short options too. -a,-- suffix-length=N use suffixes of length N (default 2) specify the suffix length of the split file-b,-- bytes=SIZE put SIZE bytes per output file split by byte, default unit byte-C,-- line-bytes=SIZE put at most SIZE bytes of lines per output file specify the maximum size of a single line The default unit byte is-d,-- numeric-suffixes use numeric suffixes instead of alphabetic uses a number as the suffix-l for split files,-- lines=NUMBER put NUMBER lines per output file splits by number of lines-- verbose print a diagnostic just before each output file is opened-- help display this help and exit-- version output version information and exit

Mode 1: specify the number of file lines after split

For txt text files, you can split the file by specifying the number of lines of the split file.

Command:

Split-l 300 large_file.txt new_file_prefix

Default generation after sharding with suffixes aa, ab, ac... And so on, of course, you can also customize the suffix.

Mode 2: specify the split file size

Split-b 10m server.log waynelog

We can also separate binaries by file size.

File merging with cat under Linux

Command:

Cat small_files* > large_file Thank you for reading this article carefully. I hope the article "how to split and merge documents under Linux" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: File suffix command size article can pass byte pattern unit help maximum and so on binary value interest at the same time multiple decimal number text Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information Docker Huawei Apple