% Step 1: Read in the two files using readlines
file1_lines = readlines('24802901.raw2');
file2_lines = readlines('23C02901.raw2');

% % Remove any empty lines (optional, depending on your data)
% file1_lines = file1_lines(file1_lines ~= "");
% file2_lines = file2_lines(file2_lines ~= "");

% Step 2: Find matching lines
[matching_lines, idx1, ~] = intersect(file1_lines, file2_lines);

% Step 3: Remove the matching lines from file1
lines_to_keep = file1_lines(~ismember(file1_lines, matching_lines));

file3_lines = readlines('23C02902.raw2');

% Step 2: Find matching lines
[matching_lines, idx1, ~] = intersect(lines_to_keep, file3_lines);

lines_to_keep = lines_to_keep(~ismember(lines_to_keep, matching_lines));


% Step 4: Write the remaining lines to a new file
writelines(lines_to_keep, 'file1_updated.txt');

fprintf('Updated file1 has been saved as "file1_updated.txt".\n');
