2018-11-29 20:55:23 +13:00
|
|
|
# csplit
|
|
|
|
|
|
|
|
> Split a file into pieces.
|
|
|
|
> This generates files named "xx00", "xx01", and so on.
|
2025-01-18 18:45:33 +05:30
|
|
|
> More information: <https://www.gnu.org/software/coreutils/manual/html_node/csplit-invocation.html>.
|
2018-11-29 20:55:23 +13:00
|
|
|
|
|
|
|
- Split a file at lines 5 and 23:
|
|
|
|
|
2024-01-09 19:54:56 +01:00
|
|
|
`csplit {{path/to/file}} 5 23`
|
2018-11-29 20:55:23 +13:00
|
|
|
|
|
|
|
- Split a file every 5 lines (this will fail if the total number of lines is not divisible by 5):
|
|
|
|
|
2024-01-09 19:54:56 +01:00
|
|
|
`csplit {{path/to/file}} 5 {*}`
|
2018-11-29 20:55:23 +13:00
|
|
|
|
|
|
|
- Split a file every 5 lines, ignoring exact-division error:
|
|
|
|
|
2025-03-26 02:30:50 +02:00
|
|
|
`csplit {{[-k|--keep-files]}} {{path/to/file}} 5 {*}`
|
2018-11-29 20:55:23 +13:00
|
|
|
|
|
|
|
- Split a file at line 5 and use a custom prefix for the output files:
|
|
|
|
|
2025-03-26 02:30:50 +02:00
|
|
|
`csplit {{path/to/file}} 5 {{[-f|--prefix]}} {{prefix}}`
|
2018-11-29 20:55:23 +13:00
|
|
|
|
2025-07-25 08:50:06 +03:00
|
|
|
- Split a file at a line matching a `regex`:
|
2018-11-29 20:55:23 +13:00
|
|
|
|
2025-07-25 08:50:06 +03:00
|
|
|
`csplit {{path/to/file}} /{{regex}}/`
|