How to delete text file some perticular lines using Matlab script
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi I have one text file and in which if variable is not matching i need to delete that lines till end For example file is like this
FESTW Cbx_asdf_gh Xyz xyz Abs abs Ster sox END
GHRT Vbx_asdf_gh Xyz ans Anstg END
GBLOS xxx_asdf_gh Sstf Sgohe END
SO if the variable is not matching with defined variable in this case last one xxx then i need to delete that whole lines but i don't know how to delete lines till END because everytime END is ending at diff position like line no is not standard so how to delete that whole lines starting from GBLOS TO END (GBLOS xxx_asdf_gh Sstf Sgohe END)
So can you help me how to delete these lines it is having 40+ end like this and some variable is not matching so i need to delete all that till end
Thank you
댓글 수: 0
답변 (1개)
Mathieu NOE
2022년 12월 5일
편집: Mathieu NOE
2022년 12월 5일
hello
its' a bit confusing.... in other words you want to keep the lines that contain a certain variable name ?
then try this :
ll = readlines('text.txt'); % read text and convert to strings
defined_variable = 'Anstg'; % if ll does not contain that variable name , delete lines where it's missing
for ci = 1:numel(ll)
tf = strfind(ll(ci),defined_variable);
if isempty(tf)
check(ci) = false;
else
check(ci) = true;
end
end
ll_out = ll(check)
댓글 수: 3
Mathieu NOE
2023년 1월 2일
편집: Mathieu NOE
2023년 1월 2일
hello
it's still not clear to me
other that you want to keep "Cbx line" i don't fully understand the rest.
If you could wirte down what is / are the key words to keep lines (or key words to delete lines) , it would make things more understandable to me
참고 항목
카테고리
Help Center 및 File Exchange에서 Language Support에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!