Re: combining many files with the same format into one file [message #46751] |
Thu, 22 December 2005 00:07  |
peter.albert@gmx.de
Messages: 108 Registered: July 2005
|
Senior Member |
|
|
Good morning,
if you happen to use a Unix / Linux computer, I'd suggest not to use
IDL at all for this purpose but rather do something like
$ cat file1 file2 ... file50 > combined_file
Assuming that the files "file1" to "file50" are your ascii files, with
this command you will end up with one file, named "combined_file" which
is nothing but the desired concatenation. Now, it is a bit tedious to
manually type in 50 filenames, so if again you are lucky and all your
files follow a unique naming convention, you can ease your life to
something like
$ cat file* > combined_file
which will do the same as the above line.
Now, if you really want to do this within IDL, you can get along with
the following lines:
f = file_search("file*", c)
line = ""
openw, out, "combines_file", /get_lun
for i = 0, c-1 do begin
openr, in, f[i], /get_lun
while not eof(in) do begin
readf, in, line
printf, out, line
endwhile
free_lun, in
endfor
free_lun, out
Cheers,
Peter
|
|
|
Re: combining many files with the same format into one file [message #46847 is a reply to message #46751] |
Thu, 22 December 2005 14:32  |
houhou
Messages: 2 Registered: December 2005
|
Junior Member |
|
|
Thanks, Peter.
Houhou
Peter Albert wrote:
> Good morning,
>
> if you happen to use a Unix / Linux computer, I'd suggest not to use
> IDL at all for this purpose but rather do something like
>
> $ cat file1 file2 ... file50 > combined_file
>
> Assuming that the files "file1" to "file50" are your ascii files, with
> this command you will end up with one file, named "combined_file" which
> is nothing but the desired concatenation. Now, it is a bit tedious to
> manually type in 50 filenames, so if again you are lucky and all your
> files follow a unique naming convention, you can ease your life to
> something like
>
> $ cat file* > combined_file
>
> which will do the same as the above line.
>
> Now, if you really want to do this within IDL, you can get along with
> the following lines:
>
> f = file_search("file*", c)
> line = ""
> openw, out, "combines_file", /get_lun
> for i = 0, c-1 do begin
> openr, in, f[i], /get_lun
> while not eof(in) do begin
> readf, in, line
> printf, out, line
> endwhile
> free_lun, in
> endfor
> free_lun, out
>
>
> Cheers,
>
> Peter
|
|
|