Getting out of sed on first NOT match

i have a large file where i want to look for any record that is is larger or smaller than 21 and if it is the case i want to report and break SED .. how can i achieve it ?
i dont want sed to scan the complete file after one non match is found.

Hello boncuk,

Since you haven't given any samples so can't test it, could you please try following and let me know if this helps you.

awk 'length($0)>21{exit} 1' Input_file

Thanks,
R. Singh

I think the long line should be reported, not the previous lines.

awk 'length>21 {print; exit}' file

With sed

sed -n '/.\{21\}./ {p; q;}' file

So:

awk 'length != 21 {print; exit}' file

EDIT: and, mayhap, sed :

sed -n '/^.\{21\}$/ !{p; q;}' file

Ah yes, I saw post#2 and thought "larger".
Then this thread and the previous thread actually have become duplicates.