redirecting output using if-then-else in awk

I am trying to filter records based on number of "|", delimiter in my application. If number of "|" is greater than 14 its a bad record, else its a good record. I have to redirect output to two different files based on the if-then-else evaluation in AWK.

if number of �|� in file_0 > 14
move those records to file_1
else
move those records to file_2

Can someone please share me the syntax as how i have to code above scenario in AWK???

Thanks in advance...

 
$ nawk -F\| '{if(NF>14){printf("%s\n",$0) >> "a.txt"}else{printf("%s\n",$0) >> "b.txt"}}' input.txt

$ cat a.txt 
a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|
a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|

$ cat b.txt
a|a|a|a|a|a|a|a|a
a|a|a|a|a|a|

1 Like

which requires the test (NF>15), because 14 delimiters mean 15 fields. The print statements can be simplified:

awk -F\| '{if(NF>15) print >> "a.txt"; else print >> "b.txt" }'