On Unix-like operating systems, the csplit command splits a file into sections, based on context lines.

This page covers the GNU/Linux version of ucsplit.

Description

csplit outputs pieces of FILE separated by PATTERN(s) to files ‘xx00’, ‘xx01’, …, and output byte counts of each piece to standard output.

  • Description
  • Syntax
  • Options
  • Examples
  • Related commands
  • Linux commands help

Syntax

csplit [OPTION]… FILE PATTERN…

Options

csplit reads standard input if FILE is specified as a dash ("-"). Each PATTERN may be:

A line OFFSET is a required ‘+’ or ‘-’ followed by a positive integer.

Examples

csplit -f cobol filename ‘/procedure division/’ /par5./ /par16./

Creates four files, cobol00…cobol03.

After editing the split files, they can be recombined into filename using the cat command as follows:

cat cobol0[0-3] > filename

cat — Output the contents of a file.sed — A utility for filtering and transforming text.split — Split a file into pieces.