#!/bin/ksh T=/tmp/$(basename $0).$$ trap "rm -f $T" EXIT trap "rm -f $T;exit 1" INT # convert spaces to underscores and then tabs to spaces # also insert single _ for missing columns, and remove # the parentheses from around "(Trial Variable)". tr ' \t' '_ ' \ | sed -e 's/ / _ /g' -e 's/(Trial_Variable)/Trial_Variable/g' \ > $T exec < $T # get the five sl4 header lines # 1 scenario file basename # 2 subject name # 3 date and time # 4 empty line # 5 first header line # 6 second header line read subject read scenario read date time read read -A a read -A b #print a: ${a[*]} #print b: ${b[*]} # combine a and b into the column labels ((i=0)) while [[ ${a[i]} != "" && ${b[i]} != "" ]] ; do if [[ ${a[i]} == _ ]] ; then label[i]=${b[i]} elif [[ ${b[i]} == _ ]] ; then label[i]=${a[i]} else label[i]="${a[i]}_${b[i]}" fi ((i++)) done a= b= # this function returns the column that has the given label # returns 255 (-1) if there is no such column label function _colno { typeset i ((i=0)) while [[ ${label[i]} != "" ]] ; do if [[ ${label[i]} == $1 ]] ; then return $i fi ((i++)) done return -1 } # this function defines variables for labels, given in the form label/var function colvars { typeset x a b c for x in $* ; do b=$(basename $x) a=$(dirname $x) _colno $a c=$? if [[ $c -eq 255 ]] ; then print -u2 -- "Couldn't find label $a in datafile" exit 1 fi eval "$b=$c" done } print scenario $scenario print subject $subject print date $date print time $time print ${label[*]} colvars Block_Name/blk Trial_Name/tr Event_Name/ev Key/r Reaction_Time/rt while read -A data ; do print $subject ${data[blk]} ${data[tr]} ${data[ev]} ${data[r]} ${data[rt]} done exit 0