#/bin/sh fn="sample.txt" counter=0 for line in cat $fn; do counter=$(( counter + 1 )) done echo $counter