필터 지우기
필터 지우기

Reading only those lines starting with a specific string

조회 수: 17 (최근 30일)
Nachiket Patki
Nachiket Patki 2018년 4월 29일
답변: Ameer Hamza 2018년 4월 29일
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

답변 (1개)

Ameer Hamza
Ameer Hamza 2018년 4월 29일
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.

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by