Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # usage:
- # split.sh log.txt 20000
- set -e
- LANG=C LC_ALL=C # 1 char = 1 byte
- PART=1
- BYTES=0
- exec 3<>"$1.part${PART}" # open file
- while IFS='' read -r line ; do
- echo "$line" >&3
- BYTES=$(( BYTES + ${#line} ))
- if (( BYTES > $2 )) ; then
- exec 3>&-
- (( PART++ ))
- exec 3<>"$1.part${PART}"
- BYTES=0
- fi
- done < "$1"
- exec 3>&- # close file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement