# create file touch c-temp # Clear out file rm c-temp # z x y u v w a b c # See how many lines the file has. z=$(cat ${1} | wc -l | sed s/\ //g) #echo ${z} # Starting to count up from the 1st line to output each line at a time and examine it x=1 # Value of how many characters you want per line d=79 # WHILE 1 ------------------------------------------------------- while [ ${x} -le ${z} ] do # Checking each specific line to see if they exceed 79 characters y=$(awk NR==${x} ${1} | wc -c | sed s/\ //g) # echo "Count - ${x} - ${y}" # Any line that exceed 79 characters are sent to see what field starting from 79 and down has a blank space # IF 1 if [ ${y} -gt ${d} ]; then u=$(echo "${d}") # Start counting down from 79 to check each character for a space # WHILE 2==================================================== while [ ${u} -gt 0 ] do v=$(awk NR==${x} ${1} | cut -c${u} | grep -c " ") # If one of the field shows that it is a space (by being greater than zero) then stop to gather all fields up to that point and then take that space and assign it a special character so we can swap it for a new line feed later. # IF 2 if [ ${v} -gt 0 ];then c=$(awk NR==${x} ${1} | cut -c1-${u} | rev | sed s/\ //1 | rev) echo "${x} - ${c}" echo "${c}" >> c-temp # Checking the characters that proceed after the first split and see of those remaining character count exceed 79 characters a=$(awk NR==${x} ${1} | cut -c${u}- | wc -c | sed s/\ //g) # The remaining character count exceeds 79 characters # IF 3 if [ ${a} -gt ${d} ];then let "w = u + d" let "u = u + 1" # echo "${w} - ${u}" # WHILE 3 while [ ${w} -gt ${u} ] do # echo "W count - ${w}" b=$(awk NR==${x} ${1} | cut -c${w} | grep -c " ") # IF 4 if [ ${b} -gt 0 ];then c=$(awk NR==${x} ${1} | cut -c${u}-${w} | rev | sed s/\ //1 | rev) echo "${x} - ${c}" echo "${c}" >> c-temp # echo "${w}" a=$(awk NR==${x} ${1} | cut -c${w}- | wc -c | sed s/\ //g) # echo "${a}" # IF 5 if [ ${a} -gt ${d} ];then u=$(echo "${w}") let "w = u + d" let "u = u + 1" # echo "${w} - ${u}" else # Output now less than 79 characters after having multiple splits c=$(awk NR==${x} ${1} | cut -c${w}-) echo "${x} - ${c}" echo "${c}" >> c-temp w=0 u=0 fi # FI 5 complete fi # FI 4 complete let "w = w - 1" done # WHILE/DONE 3 complete # Remaining character count does not exceed 79 characters else # Output now less than 79 characters after having only one split c=$(awk NR==${x} ${1} | cut -c${u}-) echo "${x} - ${c}" echo "${c}" >> c-temp u=0 fi # FI 3 complete fi # FI 2 complete let "u = u - 1" done # WHILE/DONE 2 complete # Output for lines less than 79 else c=$(awk NR==${x} ${1}) echo "${x} - ${c}" echo "${c}" >> c-temp fi # FI 1 complete let "x = x + 1" done # WHILE/DONE 1 complete ----------------------------------------