Reading only those lines starting with a specific string
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I have a text file. Now I want to read only those line which start with particular strings only. For example, I have sentences in text file as...
1_xyz_sdf_rtuy_errt
2_dsgs_sdfs_sfs_ewtw
3_sd_sddgs_ewetertert
4_....
etc
(The numbers from starting of each line will go on increasing) where you can see each line starts with a string 1 or 2 or 3 etc, so I have to check whether particular line starts with 1 if YES the find 'xyz' string from the line. similarily if line starts with 2 then find another 'xyz' string so on and so forth... Can anyone please help me?
Thank you
0 comentarios
Respuestas (1)
Ameer Hamza
el 29 de Abr. de 2018
It might be a better solution to read the entire file into memory using textscan() and then search for a particular line or string.
If you just want to search the file once or still want to incrementally search the file, then just use fgetl(), to read lines one by one from the text file and search until you reach required line.
0 comentarios
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!