Home » Linux Command Reference » UNIX/LINUX Command – csplit

UNIX/LINUX Command – csplit

NAME

csplit—Split a file into sections determined by context lines

SYNOPSIS

csplit [–sqkz] [–f prefix] [–b suffix] [–n digits] [—prefix=prefix] [—suffix–format=suffix] [—digits=digits] [—quiet] [—silent] [—keep-files] [—elide–empty–files] [—help] [—version] file pattern…

DESCRIPTION

This manual page documents the GNU version of csplit. csplit creates zero or more output files containing sections of the given input file, or the standard input if the name – is given. By default, csplit prints the number of bytes written to each output file after it has been created.

The contents of the output files are determined by the pattern arguments. An error occurs if a pattern argument refers to a nonexistent line of the input file, such as if no remaining line matches a given regular expression. After all the given patterns have been matched, any remaining output is copied into one last output file. The types of pattern arguments are

line Create an output file containing the current line up to (but not including) line line (a positive integer) of the input file. If followed by a repeat count, also create an output file containing the next line lines of the input file once for each repeat.
/regexp/[offset] Create an output file containing the current line up to (but not including) the next line of the input file that contains a match for regexp. The optional offset is a + or – followed by a positive integer. If it is given, the input up to the matching line plus or minus offset is put into the output file, and the line after that begins the next section of input.
%regexp%[offset] Like the previous type, except that it does not create an output file, so that section of the input file is effectively ignored.
{repeat-count} Repeat the previous pattern repeat-count (a positive integer) additional times. An asterisk may be given in place of the (integer) repeat count, in which case the preceding pattern is repeated as many times as necessary until the input is exhausted.

The output filenames consist of a prefix followed by a suffix. By default, the suffix is merely an ascending linear sequence of two-digit decimal numbers starting with 00 and ranging up to 99; however, this default may be overridden by either the —digits option or by the —suffix–format option. (See “Options,” next.) In any case, concatenating the output files in sorted order by filename produces the original input file, in order. The default output filename prefix is xx.

By default, if csplit encounters an error or receives a hangup, interrupt, quit, or terminate signal, it removes any output files that it has created so far before it exits.

OPTIONS

Option  Description 
–f, —prefix=prefix Use prefix as the output filename prefix string.
–b, —suffix–format=suffix Use suffix as the output filename suffix string. When this option is specified, the suffix string must include exactly one printf(3) style conversion specification (such as %d, possibly including format specification flags, a field width, a precision specifications, or all of these kinds of modifiers). The conversion specification must be suitable for converting a binary integer argument to readable form. Thus, only d, i, u, o, x, and X format specifiers are allowed. The entire suffix string is given (with the current output file number) to sprintf(3) to form the filename suffixes for each of the individual output files in turn. Note that when this option is used, the —digits option is ignored.
–n, —digits=digits Use output filenames containing numbers that are digits digits long instead of the default 2.
–k, —keep-files Do not remove output files when errors are encountered.
–z, —elide–empty–files Suppress the generation of zero-length output files. (In cases where the section delimiters of the input file are supposed to mark the first lines of each of the sections, the first output file will generally be a zero-length file unless you use this option.) Note that the output file sequence numbers will always run consecutively, starting from 0, even in cases where zero-length output sections are suppressed due to the use of this option.
–s, –q, —silent, —quiet Do not print counts of output file sizes.
—help Print a usage message and exit with a nonzero status.
—version Print version information on standard output, then exit.

Related Posts

UNIX/LINUX Command – rsync

UNIX/LINUX Command – rsync

NAME rsync – a fast, versatile, remote (and local) file-copying tool rsync Command SYNOPSIS Local: rsync [OPTION…] SRC… [DEST] Access via remote shell:Pull: rsync [OPTION…] [USER@]HOST:SRC… [DEST]Push: rsync [OPTION…] SRC… [USER@]HOST:DEST Access via rsync...

UNIX/LINUX Command – strip

UNIX/LINUX Command – strip

NAME strip—Discard symbols from object files. SYNOPSIS strip [ -Fbfdname|–target=bfdname ] [ -Ibfdname|–input-target=bfdname ] [ -Obfdname|–output-target=bfdname ] [-Rsectionname|–remove-section=sectionname ] [ -s|–strip-all ] [-S|-g|–strip-debug ][-x|–discard-all...

UNIX/LINUX Command – expand

UNIX/LINUX Command – expand

NAME expand—Convert tabs to spaces SYNOPSIS expand [–tab1[,tab2[,…]]] [–t tab1[,tab2[,…]]] [–i] [—tabs=tab1[,tab2[,…]]] [–initial] [–help] [–version] [file…] DESCRIPTION This manual page documents the GNU version of expand. expand writes the contents of each given...

UNIX/LINUX Command – uuencode

UNIX/LINUX Command – uuencode

NAME uuencode—Encode a binary fileuudecode—Decode a file created by uuencode SYNOPSIS uuencode [-m] [ file ] nameuudecode [-o outfile] [ file ]… DESCRIPTION uuencode and uudecode are used to transmit binary files over transmission mediums that do not support other...

Follow Us

Our Communities

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!

0 Comments

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

4 × five =

Shares