how can print every word in new line but skip printing if word is repeating..this is a sorted list of words
1 view (last 30 days)
Show older comments
close all;clear all;clc%creatiing word list with repeatation fid1=fopen('textfile.txt','r'); fid2=fopen('wordslist','w'); while ~ feof(fid1) new_line = fgetl(fid1); a=new_line; b=strsplit(a);c=[b(end) b]; c=cat(2,b(end),b); f=cat(2,c(1),(c(3:end))) fprintf(fid2, '%s\n', f{:}) end fclose(fid1); fclose(fid2); I want to sort wordlist and then print again while not print the repeating word. for example if output is like as bar yoyo same bar yoyo bar man i want output like this as bar man same yoyo thanks in advance
Answers (1)
Jan
on 27 Jun 2018
str = fileread('textfile.txt');
str(ismember(str, sprintf('.,\n\r'))) = ' ';
words = unique(strsplit(str, ' '));
fid = fopen('wordslist', 'w');
if fid == -1
error('Cannot open file for writing');
end
fprintf(fid, '%s\n', words{:});
fclose(fid);
0 Comments
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!