Skip to content

Instantly share code, notes, and snippets.

@gMan1990
Last active October 28, 2018 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gMan1990/39afa50492e5a4cbaf68f0ef14eb7136 to your computer and use it in GitHub Desktop.
Save gMan1990/39afa50492e5a4cbaf68f0ef14eb7136 to your computer and use it in GitHub Desktop.
文件按行数分割,且限制文件大小(非完美解决方案)
#!/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