Select rows from txt file
Show older comments
Hi,
Could someone help on how can I choose specific rows from the below sample (the original txt file is actually huge):
Stock Date Time Price Volume Stock Category > ETE 04/01/2010 10145959 18.34 500 Big Cap > ETE 04/01/2010 10150000 18.34 70 Big Cap > ETE 04/01/2010 10170000 18.34 430 Big Cap > ABC 04/01/2010 10190000 18.34 200 Big Cap > YYY 04/01/2010 10200000 18.34 100 Big Cap > ETE 04/01/2010 10250000 18.34 40 Big Cap > ETE 04/01/2010 10295959 18.34 215 Big Cap > ETE 04/01/2010 10300000 18.34 500 Big Cap > ETE 04/01/2010 10320000 18.34 500 Big Cap
For instance can I keep only rows for stock 'ABC' (column 1)?
Thanks in advance,
Panos
1 Comment
Andrew Newell
on 21 Mar 2011
Is each string between >'s supposed to be a row? If so, please format it so people know what you're talking about.
Accepted Answer
More Answers (1)
Walter Roberson
on 21 Mar 2011
0 votes
In such a case I would probably use perl. The same functionality can be written in Matlab directly but the I/O would be slower than for perl.
Anyhow, fopen() your text file, fgetl() on it to read the header, then start a loop. fgetl() on the file, compare the first N+1 characters to your target stock name followed by a blank; only save the line if you got a match; continue loop.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!