linux using csplit command to split a file example

  • 2020-06-07 05:57:11
  • OfStack

Applicable scenario

The csplit command is used to split a large file into smaller pieces and to save each fragment into a file, the csplit command wok > Split the file according to the specified pattern, save as xx00,xx01... The file.

The unassembly files are mainly split and csplit commands. If split is split by size, then csplit can be split by match

Option to explain

$ csplit -h
/[regular expression]/ # matches text styles, such as /SERVER/, from line 1 to the matching line containing SERVER. {*} # indicates that the split is repeated based on the match until the end of the file stops, and the number of times the split is specified in the form of {integer}. -s # silent mode, no other information is printed. -ES22en # specifies the number of filename suffixes to split. Such as 01, 02, 03 and so on. -f # specifies the split filename prefix. -ES24en # specifies the suffix format. For example, % 02d.log, similar to the printf parameter format in the C language.

Method of use

$ csplit filename /match/ -n2 {*} -f aa -b ".log"


Related articles: