#! /bin/bash # splits a calibration submodel detail report file into seperate files # check for argument if [ -e "${1}" ] then # the first file will be 1, so start at 0 let filecnt=0 # set so that thinks it needs a new file let prevgrep=0 # the IFS entry instructs read to ignore word delimiters and take in the whole line, leading spaces and all while IFS="" read record do #let linecnt=linecnt+1 #echo "Line: ${linecnt}" # echo "${record}" gotgrep=$(echo ${record} | grep -q '^#') if [ $? -eq 0 ] then # echo "Found comment line" if [ ${prevgrep} -eq 0 ] then # increment file counter let filecnt=filecnt+1 echo "Now writing to ${1}.${filecnt}" # remove previous instance since we are appending lines rm -f ${1}.${filecnt} fi let prevgrep=1 else # echo "Not a comment line" if [ ${prevgrep} -eq 1 ] then let prevgrep=0 fi fi echo "${record}" >> ${1}.${filecnt} done < ${1} else echo "Invocation: splitcalrun " fi