How to find and remove certain text from a text file

51 views (last 30 days)
Pineapple
Pineapple on 8 Aug 2019
Edited: Pineapple on 14 Aug 2019
Hi,
I am having trouble removing specific text from a text file. I have a long text file that contains 5 columns and many rows
I am looking for something similar to the functionality of ctrl+F and then remove all of the strings. Essentially I want to isolate the file so it just displays only positive and negative numbers next to Sum-Pnt
  3 Comments
Pineapple
Pineapple on 14 Aug 2019
@Rik I apologize. I made edits but I will restore necessary info and I have unflagged. The text file I was referring to was in the form shown below and the loop is in the next answer.
Sum-Pnt .5464 -.650 +.650 .5464 -+-+-+
Sum-Pnt .3244 -.650 +.650 .3244 -+-+-+
Sum-Pnt-.9723 -.650 +.650 -.9723 -+-+-+

Sign in to comment.

Accepted Answer

Bob Thompson
Bob Thompson on 8 Aug 2019
As I mentioned, the command would only work for one line at a time. You would need to loop it to get all the lines.
fid = fopen('myfile.txt');
line = fgetl(fid);
c = 1;
while ~isnumeric(line)
number(c) = regexp(text,'Sum-Pnt(.\d.\d+)\s+.*','tokens');
line = fgetl(fid);
c = c + 1;
end
  2 Comments
Pineapple
Pineapple on 14 Aug 2019
The loop worked once "text" was replaced with "line". Thank you for your help

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!