Remove line from text file if in the first column there is a certain character
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I have a .txt file with many rows. Short example:
$GN,074043.00,11,09,2020,00,00*
2 -0000,00 00000,00 $GN,
3 00005,00 00092,00 $GN,
4 00045,00 00042,00 $GN,
5 00005,00 00092,00 $GN,
6 00035,00 00047,00 $GN,
$GN,074136.00,11,09,2020,00,00*
7 00005,00 00092,00 $GN,
8 00025,00 00051,99 $GN,
9 00005,00 00092,00 $GN,
$GN,074152.00,11,09,2020,00,00*
10 00015,00 00056,99 $GN,
11 00005,00 00092,00 $GN,
12 00005,00 00062,01 $GN,
...
I wont to remove all lines which starting with "$" (in first column).
How can it be done?
댓글 수: 0
채택된 답변
Rik
2020년 9월 14일
Split the lines to cells and use a loop (or cellfun) to remove all elements where strcmp(contents(1),'$') is true. Then you can print the cell array to your file with
fprintf(fid,'%s\n',data{:});
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!