├── README.md ├── .gitattributes ├── Dockerfile ├── split.sh └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # textutil-split-file 2 | Split text file into 2 parts based on a provided ratio 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | *.sh text eol=lf 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nuagebec/ubuntu:latest 2 | 3 | MAINTAINER Floyd 4 | 5 | RUN apt-get update && apt-get install -y \ 6 | bc \ 7 | && \ 8 | apt-get clean && \ 9 | apt-get autoremove && \ 10 | rm -rf /var/lib/apt/lists/* 11 | -------------------------------------------------------------------------------- /split.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Reading in command line arguments 3 | 4 | for i in "$@" 5 | do 6 | case $i in 7 | -i=*|--input=*) 8 | INPUT="${i#*=}" 9 | shift # past argument=value 10 | ;; 11 | -r=*|--ratio=*) 12 | RATIO="${i#*=}" 13 | shift # past argument=value 14 | ;; 15 | -p1=*|--part1=*) 16 | PART1="${i#*=}" 17 | shift # past argument=value 18 | ;; 19 | -p2=*|--part2=*) 20 | PART2="${i#*=}" 21 | shift # past argument=value 22 | ;; 23 | # --default) 24 | # DEFAULT=YES 25 | # shift # past argument with no value 26 | # ;; 27 | *) 28 | # unknown option 29 | ;; 30 | esac 31 | done 32 | 33 | echo "INPUT = ${INPUT}" 34 | echo "RATIO = ${RATIO}" 35 | echo "PART1 = ${PART1}" 36 | echo "PART2 = ${PART2}" 37 | 38 | # Split total lines using ratio. Add 1 because csplit argument is not inclusive 39 | LINES="$(echo "$(wc -l < ${INPUT}) * ${RATIO} + 1" | bc)" 40 | # Round to integer 41 | LINES=$( printf "%.0f" $LINES ) 42 | echo "PART1 LINES = ${LINES}" 43 | 44 | csplit ${INPUT} ${LINES} -f part 45 | 46 | mv part00 ${PART1} 47 | mv part01 ${PART2} -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 floydhub 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------