Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use the csplit command of linux to split the file

Shulou Source: shulou.com Published: 2022-06-02 19:45:34 10月04日 Update

This article mainly introduces the use of linux csplit command to split the file, has a certain reference value, friends in need can refer to. Let's take a look at it with me.

The English full name of the csplit command is "context split". This command is used to split a large file into small fragments and save each fragment into a file. Fragmented files are named like "xx00" and "xx01". The csplit command is a variant of split. Split can only split files according to file size or number of lines, but csplit can split files according to their own characteristics.

Syntax parameter: csplit [parameter]

Common parameters:

-b or-- suffix-format= preset output format whose file name is xx00,xx01, etc. Users can change the output file name-f or-- prefix= preset output header string and its file name is xx00,xx01, etc. If the output header string is set to "hello", the output file name will become hello00,hello, 01... -k or-- keep-files keeps the file, even if an error occurs or interrupts execution, and cannot delete the output file name of the saved file-n or-- digits= preset, whose file name is xx00,xx01. If the user specifies that the output file name is "3", the output file name becomes-Q or-s such as xx000,xx001 or-- quiet or-- silent does not show instruction execution process-z or-- elide-empty-files delete length is 0 Byte file.

Reference example

Cut the text file filename into two pieces at the second behavior demarcation point:

[root@linuxcool ~] # csplit filename 2

Cut the text file filename into 2 pieces at the demarcation point of 120 behavior, and specify that the number of digits of the output file name is 3:

[root@linuxcool] # csplit-n 3 filename 120

Cut the text file textfile into 2 pieces at the demarcation point of 120 behavior, and specify that the leading edge of the output file name is fileName digits:

[root@linuxcool] # csplit-f fileName testfile 120

Split the file filename 8 times in 10 behavior units and specify the format of the output file name:

[root@linuxcool ~] # csplit-b "myfile%o% filename 10 {8}

Split the text file filename by every 20 behavior units:

[root@linuxcool ~] # csplit filename 20 {*}

Divide the file into two parts with the string "Chapter X" as the delimiter:

[root@linuxcool ~] # csplit filename / "Chapter X" / above is the detailed content of the file split using linux's csplit command. Have you learned anything after reading it? If you want to know more about it, welcome to the industry information!

Tags: File output file name command behavior digit text demarcation point parameter character string fragment content unit name format user reference value full name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Information macOS Shulou Tech Info MariaDB