Generate files from one file based on lines

Hi Friends,

I have a file1

file1.txt

 
1ABC 13478 aqjerh 473 343   
2hej 478 5775 24578 23892
3fhd fg 847 brjkb f99345 487
4eh ehjk 84 47589 8947 234
5784 487 738 52895 8975
6 57489 eghe9 4575 859479 
7fnbd 4y5 4iuy  458 h irh
8fjdg 74  7845 8475 5789 
94yr 48yr  4hr  erhj  reh
10fh g 874 fr b8457 hjk 
11hgf fej efjg j ghjegf 
12hj fjg jfeg feg gjgwe 
1DEF 136578 aqjrh 43 33   
2htr 478 5775 24578 2392
3fhd fg 847 brjkb f99345 487
4eh ehjk 84 47589 8947 234
5784 487 78 52895 8975
6 57489 eghe9 4575 859479 
7fnbd 4y5 4iuy  458 h irh
8fjdg 74  7845 8475 5789 
94yr 48yr  4hr  erhj  reh
10fh g 874 fr b8457 hjk 
11hgf fej efjg j ghjegf 
12hj fjg jfeg feg gjgwe 

i want to generate 2 files where frist.txt will contain the 1-9 lines which are in red in color. and second.txt will contain 1 and 10 t0 12 lines.i have this sequence through out the file.i am newbie and need help.

expected output :

 
first.txt
 
ABC 13478 aqjerh 473 343   
hej 478 5775 24578 23892
fhd fg 847 brjkb f99345 487
eh ehjk 84 47589 8947 234
784 487 738 52895 8975
 57489 eghe9 4575 859479 
fnbd 4y5 4iuy  458 h irh
fjdg 74  7845 8475 5789 
4yr 48yr  4hr  erhj  reh
DEF 136578 aqjrh 43 33   
htr 478 5775 24578 2392
fhd fg 847 brjkb f99345 487
eh ehjk 84 47589 8947 234
784 487 78 52895 8975
 57489 eghe9 4575 859479 
fnbd 4y5 4iuy  458 h irh
fjdg 74  7845 8475 5789 
4yr 48yr  4hr  erhj  reh
 
second.txt
 
ABC 13478 aqjerh 473 343 
fh g 874 fr b8457 hjk 
hgf fej efjg j ghjegf 
hj fjg jfeg feg gjgwe 
DEF 136578 aqjrh 43 33
fh g 874 fr b8457 hjk 
hgf fej efjg j ghjegf 
hj fjg jfeg feg gjgwe 

plz help

The following seems to do what you want:

awk -v f1=first.txt -v f2=second.txt '
(NR - 1) % 12 <= 8 {print > f1}
(NR - 1) % 12 == 0 || (NR - 1) % 12 > 8 {print > f2}
' file1.txt

but the results don't quite match your sample files because you have different numbers of trailing spaces between lines 1 and 13 in file1.txt and what you said you want to see on lines 1 and 5 of the output to be placed in second.txt.

In the below line, why it was not considered as 94 ?

 
94yr 48yr  4hr  erhj  reh

---------- Post updated at 11:34 AM ---------- Previous update was at 11:31 AM ----------

 
$ nawk '{a=substr($1,1,2)+0;sub("^[0-9]","",$0)}a<=9||a>12{print >> "first.txt"}a==1||a>=10&&a<=12{sub("^[0-9]","",$0);print >>"second.txt"}' a.txt
 
$ cat first.txt
ABC 13478 aqjerh 473 343   
hej 478 5775 24578 23892
fhd fg 847 brjkb f99345 487
eh ehjk 84 47589 8947 234
784 487 738 52895 8975
 57489 eghe9 4575 859479 
fnbd 4y5 4iuy  458 h irh
fjdg 74  7845 8475 5789 
4yr 48yr  4hr  erhj  reh
DEF 136578 aqjrh 43 33   
htr 478 5775 24578 2392
fhd fg 847 brjkb f99345 487
eh ehjk 84 47589 8947 234
784 487 78 52895 8975
 57489 eghe9 4575 859479 
fnbd 4y5 4iuy  458 h irh
fjdg 74  7845 8475 5789 
4yr 48yr  4hr  erhj  reh
 
$ cat second.txt 
ABC 13478 aqjerh 473 343   
fh g 874 fr b8457 hjk 
hgf fej efjg j ghjegf 
hj fjg jfeg feg gjgwe 
DEF 136578 aqjrh 43 33   
fh g 874 fr b8457 hjk 
hgf fej efjg j ghjegf 
hj fjg jfeg feg gjgwe

Hi itkamaraj,
If you look back at message #1 in this thread, you'll see that the line you asked about is shown as:

94yr 48yr  4hr  erhj  reh

rather than

94yr 48yr  4hr  erhj  reh

(the 9 is in red, but the 4 is in black).

I assumed that the intent was that the numbers in red are line numbers (in repeating sets numbered from 1 through 12) used for discussion, but not actually present in the input file. Your code sample assumes that these numbers in red actually appear in the file.

i150371485 needs to clarify the intent for us to find out which assumption was correct.