any simple statements to do this
How to remove lines that do not start with specific characters?
7 views (last 30 days)
Show older comments
The file consists of values like
v 1 2 3
v 1 2 3
vt 1 2 3
vn 1 2 3
f 1 2 3
I want only lines that start with v or f -- other lines should be removed .
How to do this? Please help me. Thanks in advance.
Is it possible using this regexprep?
Answers (2)
Walter Roberson
on 2 Jan 2013
infile = fileread('YourFileName.txt');
newfile = regexprep(infile, '^[^vf].*$', '', 'lineanchors', 'dotexceptnewline');
fid = fopen('NewFileName.txt');
fwrite(fid, newfile);
fclose(fid)
3 Comments
Jan
on 2 Jan 2013
@Sharen: Please do not post "not working" without any explanations in the forum. Do you get an error message (which one?) or do the results differ from your expectations (how?)?
See Also
Categories
Find more on Characters and Strings 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!