diff options
author | heqnx <root@heqnx.com> | 2025-05-12 20:27:03 +0300 |
---|---|---|
committer | heqnx <root@heqnx.com> | 2025-05-12 20:27:03 +0300 |
commit | dc6d6e028489996d4bfd12b28147b86e5cf0551e (patch) | |
tree | b8b5454ef776515f440697d176f4186b83574a6b | |
parent | 3ed7425efe5ad0bec184897c3eaee6c88d84554e (diff) | |
download | gists-dc6d6e028489996d4bfd12b28147b86e5cf0551e.tar.gz gists-dc6d6e028489996d4bfd12b28147b86e5cf0551e.zip |
added split-file.sh
-rw-r--r-- | split-file.sh | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/split-file.sh b/split-file.sh new file mode 100644 index 0000000..c8f785a --- /dev/null +++ b/split-file.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +if test "${#}" -ne 2; then + printf "%s\n" \ + "split file into N parts" \ + "usage: $(basename $0) <file.txt> <parts>" + exit 1 +fi + +if ! command -v split &>/dev/null; then + printf "%s\n" "split not found" + exit 1 +fi + +file="${1}" +parts="${2}" +filename="${file%.*}" +extension="${file##*.}" +total_lines=$(wc -l < "${file}") +lines_per_part=$((total_lines / parts + 1)) +split -l "${lines_per_part}" -d --additional-suffix=".${extension}" "${file}" "${filename}_" |