Get the App
SLTechnology News&Howtos  ›  Servers  › 

Linux basic command-csplit

Shulou Source: shulou.com Published: 2022-06-02 06:46:46 11月02日 Update

Csplit

Splits the file according to the specified pattern. The default output file names are xx00, xx01, xx02, and so on. The instruction shows the size of each output file. The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.

1. Grammar

Csplit [options] file format

2. List of option formats

Option

Description

-- hep

Show help documentation

-- version

Display version information

-b |-- suffix-format=FORMAT

Use sprintf format instead of d

-f name |-- prefix=PREFIX

Specify the prefix name of the output file instead of using "xx"

-k |-- keep-files

Do not delete the wrong output file

-n num

Specifies the number of characters in the output file name, which refers to the sequence number length in the file name

-z |-- elide-empty-files

Delete empty file

-s |-- quiet |-- silent

Does not display the size of the output file

Format

Description

Integer number

Does not include the specified line and uses it as the file block boundary

/ expression / [offset]

Do not include matching lines and use them as file block boundaries

% expression% [offset]

Skip the number of matching lines in advance and use it as the file partition boundary

{Integer}

Repeats the previously specified pattern a specified number of times

{*}

Repeat the previously specified pattern as many times as possible

3. Examples

1) split the file from line 2

[root@localhost weijie] # cat 1.c / / View the file

Hello world

I am david.

I love linux

Love code.

[root@localhost weijie] # csplit 1.c 2 / / split from line 2, and output the split file size

fourteen

thirty-nine

[root@localhost weijie] # ls

11.c 1.c 1.c ~ 2.c 3.c 4.c 4.c ~ 5.c 6.c test Tsplitaa Tsplitab Tsplitac Tsplitad xaa xab xac xx00 xx01

[root@localhost weijie] # cat xx00 / / View the output file

Hello world

[root@localhost weijie] # cat xx01

I am david.

I love linux

Love code.

2) set the name of the generated file

[root@localhost weijie] # csplit-n 3-f te 1.c 3 / / specifies the output copy prefix te with a length of 3 names. Here, the sequence number in the file name is 3 lengths.

twenty-seven

twenty-six

[root@localhost weijie] # ls

11.c 1.c 1.c ~ 2.c 3.c 4.c 4.c ~ 5.c 6.c te000 te001 test

[root@localhost weijie] # cat te000 / / View files

Hello world

I am david.

[root@localhost weijie] # cat te001

I love linux

Love code.

A Linux learning platform has been made, and a prototype has come out at present, which you can refer to and use.

Link: https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ password: n7bk

Tags: File output file name format name size pattern boundary length prefix sequence number integer degree expression offset command information character instance password Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Linux NVidia MySQL Shulou Information