フィルターのクリア

How to remove certain lines of text in a text file

3 ビュー (過去 30 日間)
jgillis16
jgillis16 2015 年 6 月 18 日
コメント済み: Star Strider 2015 年 6 月 18 日
I am trying to remove certain lines of text present in one text file. All these lines needing to be removed are present in another text file I have created. Both are attached. The text file that needs the removal is labeled 'SAMPLEFILE.txt', while the file containing the lines to be removed from 'SAMPLEFILE.txt' is named 'NewGalaxy.txt'.
  3 件のコメント
jgillis16
jgillis16 2015 年 6 月 18 日
files were posted for reference. I need help writing the code.
Star Strider
Star Strider 2015 年 6 月 18 日

サインインしてコメントする。

採用された回答

Jan
Jan 2015 年 6 月 18 日
DataS = fileread('SAMPLEFILE.txt');
% Perhaps you have to fix the linebreaks:
DataS = strrep(DataS, char([13,10]), char(10));
Data = regexp(DataS, char(10), 'split');
PatternS = fileread('NewGalaxy.txt');
PatternS = strrep(PatternS , char([13,10]), char(10));
Pattern = regexp(PatternS , char(10), 'split');
Match = setdiff(Data, Pattern);
% Do you want to create a new file?
fid = fopen('NewFile.txt', 'w');
if fid < 0; error('Cannot open file.'); end
fprintf(fid, '%s\n', Match{:});
fclose(fid);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-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