• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

csplit: command not found

by Deepika

The csplit command is a utility in Linux that is used to split a file into multiple smaller files based on specified criteria. It can split a file based on the occurrence of a particular string or pattern, or at fixed intervals of lines or bytes.

Here is an example of using the csplit command to split a file into multiple smaller files based on the occurrence of a particular string:

# csplit INPUT_FILE '/PATTERN/' '{*}'

This will split the INPUT_FILE into multiple smaller files, with each file containing all of the lines up to (but not including) the next occurrence of the PATTERN string. For example, if you have a file named “input.txt” that contains the following lines:

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

And you want to split the file into multiple smaller files based on the occurrence of the string “Line 5”, you can use the following command:

# csplit input.txt '/Line 5/' '{*}'

This will create two new files: “xx00” and “xx01”, with the following contents:

xx00:

Line 1
Line 2
Line 3
Line 4

xx01:

Line 6
Line 7
Line 8
Line 9
Line 10

If you encounter the below error while running the command csplit:

csplit: command not found

you may try installing the below package as per your choice of distribution:

Distribution Command
Debian apt-get install coreutils
Ubuntu apt-get install coreutils
Alpine apk add coreutils
Arch Linux pacman -S coreutils
Kali Linux apt-get install coreutils
CentOS yum install coreutils
Fedora dnf install coreutils
OS X brew install coreutils
Raspbian apt-get install coreutils

csplit Command Examples

1. Split a file at lines 5 and 23:

# csplit file 5 23

2. Split a file every 5 lines (this will fail if the total number of lines is not divisible by 5):

# csplit file 5 {*}

3. Split a file every 5 lines, ignoring exact-division error:

# csplit -k file 5 {*}

4. Split a file at line 5 and use a custom prefix for the output files:

# csplit file 5 -f prefix

5. Split a file at a line matching a regular expression:

# csplit file /regular_expression/

Filed Under: Linux

Some more articles you might also be interested in …

  1. lastcomm: command not found
  2. “git format-patch” Command Examples
  3. How to Change Default Port of Apache On RHEL/CentOS 7
  4. nsenter Command Examples in Linux
  5. foreman Command Examples in Linux
  6. git lfs: Work with large files in Git repositories
  7. sacctmgr: command not found
  8. How to Configure ACL(Access Control Lists) in Linux FileSystem
  9. tcpdump: command not found
  10. ffplay: A simple and portable media player using the FFmpeg libraries and the SDL library

You May Also Like

Primary Sidebar

Recent Posts

  • glab Command Examples
  • “glab repo” Command Examples
  • “glab release” Command Examples
  • “glab pipeline” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright