Dear Mingwu, I'm sorry, there were two other mistakes in the code I suggested: An * was missing in the read and in the write statement. The following works (using an f95 compiler): Program MBAI character :: file*12, line*80 open(10,file='data.txt') do i=1,3 write(file,'("data",i0,".txt")') i open(11,file=file) do read(11,*,iostat=ios) line ! This asterisk ^ was missing ! if (ios /= 0) exit write(10,*) trim(line) ! This asterisk ^ was missing ! end do close (11) end do end If you do not have an f95 compiler available, you should replace the statement write(file,'("data",i0,".txt")') i by the following two statements: write(file,'(i6)') i file='data'//trim(adjustl(file))//'.txt' I tested both versions with your test data sets. The above program should also work with any number of columns in the data input files, as long as the line length does not exceed 80 characters. If this is the case you would have to increase the character length in the 'line' declaration appropriately. Good luck. Roland +----------------------------------------------------------------------+ | Roland Schilling Home-Office: +49(89)32929-670 | | Max-Planck-Institut fuer Quantenoptik Phone: +49(89)32905-265 | | Hans-Kopfermann-Str. 1 Fax: +49(89)32905-200 | | D-85748 Garching E-mail: [log in to unmask] | | Germany http://www.geo600.uni-hannover.de | +----------------------------------------------------------------------+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%