collect data from files

there are 200 files named file1_0.pdb,file1_60.pdb etc....it looks like:

ATOM      1  N   VAL     1       8.897 -21.545  -7.276  1.00  0.00
ATOM      2  H1  VAL     1       9.692 -22.015  -6.868  1.00  0.00
ATOM      3  H2  VAL     1       9.228 -20.766  -7.827  1.00  0.00
ATOM      4  H3  VAL     1       8.289 -22.236  -7.693  1.00  0.00
TER
ATOM      5  CA  VAL     1       8.124 -20.953  -6.203  1.00  0.00
ATOM      6  HA  VAL     1       8.072 -19.874  -6.345  1.00  0.00
ATOM      7  CB  VAL     1       6.693 -21.515  -6.176  1.00  0.00
ATOM      8  HB  VAL     1       6.522 -22.024  -5.227  1.00  0.00
ATOM      9  CG1 VAL     1       5.684 -20.370  -6.330  1.00  0.00
ATOM     10 1HG1 VAL     1       5.854 -19.861  -7.279  1.00  0.00

i have to extract the part before TER and put in a different file...this has to be done on all 200 files...can anyone help me out....!!

What do you have so far and where exactly are you stuck?

i know that a pattern can be matched by grep...like grep "pattern" file...but i dont know how to get next lines after matching pattern

try with sed

Sed - An Introduction and Tutorial

thanks 4 so much help

---------- Post updated at 11:39 PM ---------- Previous update was at 12:01 AM ----------

I did something like this...

for i in *.pdb; do sed -n '1,/TER/q;p' $i > ${i/File/}; done

this will name all new files the same as original only the "File" is removed. E.g:
File10_0.pdb is processed and file created is 10_0.pdb....
I just have to add "file" before the name like: file10_0.pdb....
can someone plz modify my code....

try this.

 
nawk ' { fn=FILENAME ".out"; if($0!~/^TER/){printf("%s\n",$0) >> fn}} /TER/ {exit} ' *.pdb

---------- Post updated at 01:43 PM ---------- Previous update was at 01:36 PM ----------

nawk '/TER/ {exit} {fn=FILENAME ".out"; printf("%s\n",$0) >> fn}' *.pdb

output files will be created as filename.pdb.out