-3

I have this file, I want to print all the lines that are not of size 21.

PASY$ type a.a
000008050110010201NNN
000008060810010201NNN
21212000008070110010201NNN
000008080310010201NNN
000008090510010201NNN
000008050110010201NNN
000008060310010201NNN
00008070110010201NNN
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

2 Answers2

1
$ sed '/^.\{21\}$/d;q' input-file

sed will delete (and therefore not print) the first line with precisely 21 characters between the beginning and end of the line (the actual file will not be modified despite the use of scary words like "delete"). If such a line is found, it immediately will stop processing further lines.

DopeGhoti
  • 76,081
  • DopeGhoti how can i get out of the sed one a single sed matching record is found . in my case as soon as a record that is not of size 21 is found i want to report and exit sed. – Ahmad S May 16 '18 at 18:59
  • By using the q command as I will shortly illustrate in an edit to my answer. – DopeGhoti May 16 '18 at 19:16
  • 1
    @AhmadS Your question asks specifically to print all lines that are not 21 characters long. You are changing the question as you go. – Kusalananda May 16 '18 at 19:24
0
sed -n '/^.....................$/!p' < input-file

If there are not 21 characters between the beginning (^) of the line and the end ($) of the line, print it.

More positively, delete lines that are 21 characters long (printing other lines by default):

sed '/^.....................$/d' < input-file
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255