Advertisement
Guest User

Untitled

a guest
Dec 29th, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.38 KB | None | 0 0
  1. # usage:
  2. # split.sh log.txt 20000
  3. set -e
  4. LANG=C LC_ALL=C  # 1 char = 1 byte
  5. PART=1
  6. BYTES=0
  7. exec 3<>"$1.part${PART}"  # open file
  8. while IFS='' read -r line ; do
  9.     echo "$line" >&3
  10.     BYTES=$(( BYTES + ${#line} ))
  11.     if (( BYTES > $2 )) ; then
  12.         exec 3>&-
  13.         (( PART++ ))
  14.         exec 3<>"$1.part${PART}"
  15.         BYTES=0
  16.     fi
  17. done < "$1"
  18. exec 3>&-  # close file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement