I need to identify the same lines between the two text files, mwithrm21.txt and virgomrmdist.txt, based on column 7 of each files. These matches should then be exported into a new text file, while removing the matched lines from mwithrm21.txt.
I have attached the text files.
I drafted the code below:
content1 = fileread( 'mwithrm21.txt' ) ; content2_rows = strsplit( fileread( 'virgomrmdist.txt' ), sprintf( '\n' )) ; found = cellfun( @(s)~isempty(strfind(content1, s)), content2_rows ) ; output_rows = content2_rows(found) ; fId = fopen( 'similarvclf.txt', 'w' ) ; fprintf( fId, '%s\n', output_rows{:} ) ; fclose( fId ) ; output_rows = content2_rows(~found) ; fId = fopen( 'mwithrm21_new.txt', 'w' ) ; % Remove the '_new' for overwriting original.
fprintf( fId, '%s\n', output_rows{:} ) ; fclose( fId ) ;
But, I do not know how to make it specific to only searching column 7 and then exporting the entire matched line to a new text file.
Best Answer