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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. latte-dock Command Examples in Linux
  2. How to Move Swap From Disk Partition to LVM Volume in Linux
  3. foreman: command not found
  4. How to find the mounting options of currently mounted filesystem
  5. inotifywait Command Examples in Linux
  6. How to Check if any of the RPM files were tampered with
  7. Medusa Command Examples in Linux
  8. acpi Command Examples in Linux
  9. cuyo: command not found
  10. ifconfig: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright