#!/bin/sh # # greps and reformats shielding values from multiple logs ecuts="19 20 21 22 23 24 25 26 27" # check for given tag if [ -z "$2" ]; then echo "Usage: $0 <#row>" echo " gives the prefix of the logs up to the cut values, e.g. tms_tm_1-25_25Ht.1.e127 then tag is \"tms_tm_1-25\"" echo " <#row> gives the number of rows on the final output" exit 1 else tag=$1 rows=$2 fi # grep the stuff array=(`for i in $ecuts; do echo ${i}; grep shielding\ \ : ${tag}_${i}Ht*e* | awk -F": " {'print $2'} | tr . ,; done`) # now do the fancy stuff with the field delimiters, to reinterpret the array as a list of lines old_IFS=$IFS IFS=' ' # generate list for loop count=${#array[@]} echo total number of entries: $count let cols="$count / $rows" let current="$cols * $rows" echo -n "Comparing $current to $count: " if [ "$current" -lt "$count" ]; then let cols=$cols+1 echo " increasing by one." else echo "fine." fi echo "total number of columns and rows: ($cols, $rows)" # and finally print out in rearranged way j=0 while [ "$j" -lt "$rows" ]; do i=0 while [ "$i" -lt "$cols" ]; do let current="$i * $rows + $j" if [ "$current" -lt "$count" ]; then echo -e -n "${array[$current]}\t" fi let i=$i+1 done echo -e -n "\n" let j=$j+1 done IFS=$old_IFS exit 0