#!/bin/sh
#
#	Thomas Baeck,	July 03, 1992		GENEsYs 1.0
#	
#
#	USAGE: gacols <col-nr1> ... <col-nrn>
#
#	Several colums can be extracted from a data table
#	by giving the colum numbers of the colums which should 
#	be extracted. The output can be written to a file using >.
#	
#	Example: cat file | cols 1 3 > data
#		 extracts columns 1 and 3 from file and creates file data.
#

	TMP=/tmp/cols.$$

	if [ $# = 0 ]
	then
		echo "USAGE: cols <col1> ... <coln>"
		exit
	fi

	echo -n "(\$1 != \"#\")	{ print" > $TMP		# ignore comments
	SEP=" "
	for i in $* 
	do
		echo -n "$SEP\$$i" >> $TMP
		SEP=","
	done
	echo ";}" >> $TMP
	
	awk -f $TMP -

	rm $TMP
