#!/bin/sh

COLS_IN_SET=12
COLS_BEGIN=1
CHECK_ROW=2

if [ -z "$1" ]; then
	# no file was given
	echo
	echo "Usage: $0 <file to check> [in which row to check]"
	echo
	exit 1
else
	# save file name for later use
	FILE=$1
fi

if [ ! -z "$2" ]; then
	# if second parameter is given, it's row in which we should check number of sets
	CHECK_ROW=$2
fi

# get number of columns in given line
COLS=`head -$CHECK_ROW $FILE | tail -1 | sed -r "s/\s+/ /g" | sed "s/ /\n/g" | wc -l`

# calc number of sets
SETS=$(( ($COLS - $COLS_BEGIN) / $COLS_IN_SET ))

echo "There are $SETS sets in line in file $FILE (checked in line $CHECK_ROW)."

