read -p "Enter file name " fname read -p "Enter the search " pattern read -p "max " max if [ -f "$fname" ] then iter=0 result=($(grep -i "$pattern" "$fname" )) for i in "${result[@]}" do ((iter ++)) if (($iter > $max)); then break fi echo $i done fi