Hope it helps !!!
-bash-4.1$ awk -v a=3 -v b=1 'c<a{print b $0; c+=1} c==a{c=0;b+=1}' file
1asdasdasd
1asdas
1asd
2asd
2asd
2asd
3as
3asd
-bash-4.1$ awk -v a=4 -v b=1 'c<a{print b $0; c+=1} c==a{c=0;b+=1}' file
1asdasdasd
1asdas
1asd
1asd
2asd
2asd
2as
2asd
EDIT After testing two different codes (this one and the andswered by @Ed Morton), i´ve observed quite significant differences in performance between them:
$ cat lanza.sh
date
awk -v x=3 '{print (NR%x?c+1:++c), $0}' file.dat > file.dat1
date
awk -v a=3 -v b=1 'c<a{print b" "$0; c+=1} c==a{c=0;b+=1}' file.dat > file.dat2
date
./lanza.sh
EXEC1
jueves, 7 de mayo de 2015, 22:01:17 CEST
jueves, 7 de mayo de 2015, 22:02:41 CEST
jueves, 7 de mayo de 2015, 22:04:09 CEST
EXEC2 (REVERSE ORDER FOR AWKS IN lanza.sh)
jueves, 7 de mayo de 2015, 22:07:56 CEST
jueves, 7 de mayo de 2015, 22:09:24 CEST
jueves, 7 de mayo de 2015, 22:11:01 CEST
EXEC3 (REVERSE ORDER FOR AWKS IN lanza.sh)
jueves, 7 de mayo de 2015, 22:12:14 CEST
jueves, 7 de mayo de 2015, 22:13:57 CEST
jueves, 7 de mayo de 2015, 22:15:20 CEST
$ wc -l file.dat
30522352 file.dat
$ wc -l file.dat1
30522352 file.dat1
$ wc -l file.dat2
30522352 file.dat2
As can be seen , the different performance of two codes is about 5%-10% better with module (%) operator (with @Ed Morton´s code). Maybe more checking is needed, but the difference is quite significant at the first try!
equal or minus comparator times -> 1m28s, 1m37s, 1m43s
module (%) comparator times -> 1m24s, 1m28s, 1m33s