blob: c8f785a17c33322ffb1778f5cb00bbda0788a7e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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}_"
|