header="Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util" deviceList=$(more $1 | awk '/Device/,/Time:/' | awk '{if($1 != "Device:" && $1 != ""){if(match($1,"/")){split($1,a,"/");print a[2];}else print $1;}}' | sort | uniq | sed 's/://g') for curDevice in $deviceList; do echo "Processing $curDevice" if [[ $curDevice == "Time" ]]; then echo "Time " > $curDevice'.csv' more $1 | grep $curDevice | awk '{print $2" ";}' >> $curDevice'.csv' else echo $header'-'$curDevice > $curDevice'.csv' more $1 | grep $curDevice' ' >> $curDevice'.csv' fi done fileList=$(ls *.csv | awk '{if(!match($0,"Time")){print $0;}}') for curFile in $fileList; do paste Time.csv $curFile > $curFile.tmp mv $curFile.tmp $curFile done rm Time.csv -rf