LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

csplit

split files by context patterns

TLDR

Split a file starting second part at line 10
$ csplit [path/to/file] 10
copy
Split a file into three parts at lines 7 and 23
$ csplit [path/to/file] 7 23
copy
Start a new part at every 5th line
$ csplit [path/to/file] 5 {*}
copy
Split every 5th line, ignoring division errors
$ csplit -k [path/to/file] 5 {*}
copy
Use a custom prefix for output files
$ csplit [path/to/file] 5 -f [prefix]
copy
Split above first line matching a regex
$ csplit [path/to/file] /[regex]/
copy

SYNOPSIS

csplit [options] file pattern...

DESCRIPTION

csplit splits a file into pieces based on context (line numbers or patterns). It generates files named xx00, xx01, etc. by default.Unlike split which divides by size, csplit divides by content structure, making it useful for splitting log files, configuration files, or documents at specific boundaries.

PARAMETERS

-f, --prefix prefix

Use specified prefix instead of 'xx'
-k, --keep-files
Don't remove output files on error
-n, --digits digits
Number of digits in output filename
-s, --quiet
Don't print byte counts
{n}
Repeat previous pattern n times
**{*}**
Repeat previous pattern as many times as possible

INSTALL

sudo apt install coreutils
copy
sudo dnf install coreutils
copy
sudo pacman -S coreutils
copy
sudo apk add coreutils
copy
sudo zypper install coreutils
copy
brew install coreutils
copy
nix profile install nixpkgs#coreutils
copy

CAVEATS

Part of GNU coreutils. Without -k, output files are deleted if an error occurs. Pattern repetition with {*} will fail if the pattern doesn't divide the file evenly (use -k to keep partial output).

SEE ALSO

split(1), cut(1), head(1)

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid