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?

采纳的回答

Rik
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 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by