nawk -- separation of records on basis of number of fields

A file file1.txt exists having records like

The delimiter being "|"

X|_|Y|_|Z|| (number of fields 7)
A|_|B|
| (number of fields 5)
X|_|Z|_|H|| (number of fields 7)
A|_|D|_|S|
| (number of fields 7)
R|_|F|_|D|| (number of fields 7)
C|_|hbh|_|jnsdj|_|jhsd|
| (number of fields 9)
C|| (number of fields 3)
X|_|FD|_|S|
| (number of fields 7)

I want all the records where number of fields are less than 7 using a nawk command if possible.

Sample Output
A|_|B||
C|
|

Hi,

Here a solution. Try it:

$ awk --version | head -1
GNU Awk 3.1.6
$ cat infile
X|_|Y|_|Z|_|
A|_|B|_|
X|_|Z|_|H|_|
A|_|D|_|S|_|
R|_|F|_|D|_|
C|_|hbh|_|jnsdj|_|jhsd|_|
C|_| 
X|_|FD|_|S|_|
$ awk 'BEGIN { FS="|"; } NF < 7' infile
A|_|B|_|
C|_|

Regards,
Birei

nawk -F \| 'NF<7' infile

Thanks berei :b:

Can u just explain each parameter of your awk command.

$ cat script.awk
# Set field separator to pipe '|'.
BEGIN { FS="|"; } 
# If there are less of seven fields in a line, print it. The print statement of 
# the line is the default action. It would be equivalent to:
# NF < 7 { print $0 }
NF < 7

Regards,
Birei