Find string in txt and delete searched string line
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Bloodyrhyme
le 26 Avr 2019
Commenté : Bob Thompson
le 26 Avr 2019
I have a text file.
Example
Bloody, 123456, Rhyme
Fine,6542445,Fate
Faith,9875415,Empty
Faith,45152123,New
I want to search for 'Faith' and i want to delete all Faith lines or i want to search for 'empty' and i want to delete all empty lines.
this is good but its delete all info until searched string, not searched string line.
0 commentaires
Réponse acceptée
Bob Thompson
le 26 Avr 2019
You can use Jan's method from the linked question to find your lines. Then once you have found them turn them into blank lines (I'm assuming that's also what you mean by 'emtpy'). Once you have found all of the lines, using logic indexing to remove all blanks.
Index = find(strcmp(CStr, SearchedString), 1); % Find lines with 'Faith'
CStr(Index) = []; % Blank found lines
CStr = ~isempty(CStr); % Remove any empty lines, may need ~isempty([CStr(:)]);
2 commentaires
Bob Thompson
le 26 Avr 2019
That's fine. The 'simplest' way to look for multiple words is to run the search multiple times, once for each word, and blank out the respective lines.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!