#!/bin/bash outfile="" infile="restofgreatbook.txt" tempfile="restofgreatbook.txt.copy" split(){ outfile=$(head -n 1 $infile).txt headline=$1 tailline=$(($1+1)) if [[ $1 != "" ]]; then echo $headline echo $tailline clear head -n $headline $infile echo " " # echo " " echo "Lines count (102 for 100 items, 52 for 50 items): "$headline yn=y read -p "Continue with this list? [Y/n]" yn case $yn in [Yy]*) head -n $headline $infile > "$outfile" cp $infile $tempfile tail -n +$tailline $tempfile > $infile ;; [Nn]*) echo "split aborted" exit ;; esac else echo "missing number" echo "use 'greatSplitter.sh count | head' to get the next line number " exit 1 fi # echo "hello test" # echo $headline # echo $tailline echo $outfile echo $1 } linecount(){ let count=0 while read line; do let count=$count+1 if [ "$line" = "" ]; then echo $count echo $line fi done < $infile } case $1 in count) linecount | head -n 1 ;; split) split $(linecount | head -n 1) ;; esac