you might want to replace the awk code with that below. and calling it with awk -F[ ' /\[[[:digit:]]+\]/ { for (i=2; i <= NF; i++ ) { tmp=$i; sub(/\].*$/, "", tmp); if (int(tmp) > 10 && int(tmp) < 989 ){ print; break; } } } ' or similar. or at least change the /\[[[:digit:]]+\]/ { line