Last active
October 28, 2018 08:50
-
-
Save gMan1990/39afa50492e5a4cbaf68f0ef14eb7136 to your computer and use it in GitHub Desktop.
文件按行数分割,且限制文件大小(非完美解决方案)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# usage: bash this.sh lines lineBytes file toDir | |
lines=$1 | |
lineBytes=$2 | |
file=$3 | |
toDir=$4 | |
if [ "Darwin" = "$(uname)" ]; then | |
# MacOS: brew install coreutils | |
split="gsplit" | |
else | |
split="split" | |
fi | |
mkdir -p "$toDir" | |
$split -l "$lines" "$file" "$toDir/" | |
cd "$toDir" || exit | |
for item in *; do | |
if [ "$(wc -c <"$item")" -gt "$lineBytes" ]; then | |
$split -C "$lineBytes" "$item" "${item}_" | |
rm "$item" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment