Используяawk
(это было бы проще):
awk 'length != 21 { printf("Line of length %d found\n", length); exit }' file
Или, как часть сценария оболочки,
if ! awk 'length != 21 { exit 1 }' file; then
echo 'Line of length != 21 found (or awk failed to execute properly)'
else
echo 'All lines are 21 characters (or the file is empty)'
fi
Использованиеsed
:
sed -nE '/^.{21}$/!{p;q;}' file
С помощью GNU sed
вы могли бы
if ! sed -nE '/.{21}$/!q 1' file; then
echo 'Line with != 21 characters found (or sed failed to run properly)'
else
echo 'All lines are 21 characters (or file is empty)'
fi