#!/bin/bash # # script to combine separate data files to produce something gnuplot's # histogram feature can use. # # filenames hardcoded for the example of interest, but this could be # revised to be more general. # # (yes, writing the script was a lot more work than just combining and # editing the files with paste and vim, but it was more fun?) # infiles="c-library.dat java-library.dat lcg.dat" outfile=combined.dat tmp=tmp-$$ tmptmp=tmp-tmp-$$ # extract first column from data, checking that it matches in all files for f in $infiles do awk '{ print $1 }' < $f > $tmptmp if [ -e $tmp ] then cmp $tmp $tmptmp 1>/dev/null 2>/dev/null if [ $? -ne 0 ] then echo "first columns do not match" exit 1 fi else mv $tmptmp $tmp fi done # extract second column from each file and combine with previous result for f in $infiles do awk '{ print $2 }' < $f | paste $tmp - > $tmptmp mv $tmptmp $tmp done ( echo -n "#" for f in $infiles; do echo -n " $f"; done echo "" cat $tmp ) > $outfile rm $tmp