Splitting files into 100 files with field value

I want a script to split my file upon the last field (15)
As file

A,b,c,.......,01
C,v,n,.......,02
C,r,v,........,01
F,s,a,........,03
X,y,d,........,99

To make output


01.txt
A,b,c,.......,01
C,r,v,........,01

02.txt
C,v,n,.......,02

.
.
.
99.txt

I've used awk

Awk -F"," '{print > $12}' file name.  
And using    Print >$12 ; close($12)

But not working error: too many outputs
It saves max 10 so how can I do this task in script to perform it so fast as it depends on time
Thnx a lot

Hi
if I understand correctly this is what you want

awk -F, '{print $NF}' file.to.split.txt| sort -u| while read FILE
do 
grep ${FILE}$ file.to.split.txt >> ${FILE}.txt
done

Try

 awk -F, '{ print > $NF".txt" }' file

You say you used print>$12 and close($12) , could we have a look at how you used it in your script?

For

Awk -F, '{print >$12 ; close($12) }'
Awk -F, '{print >$12}' 
Same error
Awk 2 many output files 10

---------- Post updated at 06:38 AM ---------- Previous update was at 06:38 AM ----------

For

Awk -F, '{print >$12 ; close($12) }'
Awk -F, '{print >$12}' 
Same error
Awk 2 many output files 10

if its something which you are aware the limit then u can try something like this....

nawk '{for(x=1;x<100;x++) {if($NF~x) print > x}}' input.txt

Thanks
Sha

@franzo
Thnx man but script get me error usage : file [-h] [-m file ] and no output I hope when we can fix it , it can process in short time

Could you retest and post hte command line output? awk is written with a lower case "a" so that probably is not actual commmand line output..

bash-2.05$ awk -F"," '{ print > $12 ; close($12)}' file.txt 
awk: too many output files 10
 record number 11
bash-2.05$ awk -F"," '{ print > $12 }' file.txt 
awk: too many output files 10
 record number 11

---------- Post updated at 06:52 AM ---------- Previous update was at 06:51 AM ----------

---------- Post updated at 06:53 AM ---------- Previous update was at 06:52 AM ----------

thnx shahul but i got this result

nawk: syntax error at source line 1
 context is
        {for(X=1;X<100;X++){if($12~X) >>>  print>X. <<< txt}}
nawk: illegal statement at source line 1

Highlighted one doesn't look like column 12 entry.

Please try with $NF as suggested in my script(post # 3) and paste results.

@ pamu thnx and do u mean
its the 12th column at my file i ve tried

awk -F, '{ print > $NF".txt" }' file
 
awk: too many output files 10
 record number 14
 
awk -F, '{ print > $12".txt" }' file

awk: too many output files 10
 record number 78

Hi
the script of teefa is correct, the file maybe corrupted?

Hi teefa,

have just tried something and below are the results...

nawk -F, '{for(x=1;x<100;x++) {if($NF~x) {{x=x".txt"}{print > x}}}}' input.txt
-rw-rw-rw-   1 user   user        11 Feb 26 12:28 4.txt
-rw-rw-rw-   1 user   user        11 Feb 26 12:28 3.txt
-rw-rw-rw-   1 user   user        22 Feb 26 12:28 2.txt
-rw-rw-rw-   1 user   user        10 Feb 26 12:28 1.txt