separate the file according to the number of fields

I have a file which is delimetered by ',' i need to filter out a file with respect to the number of fileds in each line.

a,s,d,f,g,h,j,k,l
1,2,3,3,4,5,6,7,6
a,2,3
4,5,6,7

in this
i neeed to filter out the lines with 8 column to another file and rest to another file.
so

a,s,d,f,g,h,j,k,l
1,2,3,3,4,5,6,7,6

will go to first.txt
all the rest should go to second.txt

any help?

You have not any lines with 8 fields. But

awk -F, -vN=8 '                                                              
NF == N { print > "file1" }
NF != N { print > "file2" }
' INPUTFILE
1 Like

Example has up to 9 columns.

$> awk -F, 'NF==9 {print > "file_1"; next} {print > "file_2"}' infile
$> cat file_1
a,s,d,f,g,h,j,k,l
1,2,3,3,4,5,6,7,6
$> cat file_2
a,2,3
4,5,6,7
1 Like

Thanks Boss, It worked the way i want.. thanks a lot..