reading a writing to a text file

조회 수: 2 (최근 30일)
Azza
Azza 2012년 6월 12일
Hi,
I have a large textfile and ~ 3GB and I want to select only certain lines and save these lines in a new file. I am reading the files in chunks and for each chunk of data I want to choose the lines that I want and write them into the new file, then go back and read another chunk and so on until I reach the end of file. I have tried to save these lines in the new file by opening a new file using fopen 'w' and fprint my lines and then closing the file using fclose for each chunk of data that I read . However, I found that my data gets deleted in each fopen and fclose. I was wondering if there is an efficient way for the lines that I want from each chunk of data to be saved into the new file. I was also wondering if this method of reading and writing the data can be done by saving the data in a .mat file, because I have read that .mat files provide an efficient way of reading the data. I will be grateful to get any help regarding this.
Best wishes
AA

채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 12일
Use 'a' instead of 'w'
  댓글 수: 1
Geoff
Geoff 2012년 6월 12일
Or you could use 'w' and just keep the file open until you're finished with it.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azza
Azza 2012년 6월 19일
Many thanks Walter and Geoff...I think 'a' instead of 'w' is working perfectly with me.
Cheers
Azza

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by