How to delete header lines at the beginning and from the middle of a text file

1 次查看(过去 30 天)
Hello
I have a text file which contains data in the following way -
Series_1_2
Sweep_1_2_1 5.362E+04 2018/04/03 14:53:42.633
"Index" "Time[s]" "Imon-1[A]" "Time[s]" "Emon-1[V]"
0 0 -9 0 4
1 1 -9 1 5
2 2 -8 2 5
3 3 -9 3 5
Sweep_1_2_2 5.364863300E+04 14:54:08.633 2018/04/03 14:53:42.633
"Index" "Time[s]" "Imon-1[A]" "Time[s]" "Emon-1[V]"
0 0 -9 0 4
1 1 -9 1 5
2 2 -8 2 5
3 3 -9 3 5
I want to delete all the extra header lines and the empty lines in there and just keep the 5 columns of data so it looks like
0 0 -9 0 4
1 1 -9 1 5
2 2 -8 2 5
3 3 -9 3 5
0 0 -9 0 4
1 1 -9 1 5
2 2 -8 2 5
3 3 -9 3 5
I tried using regexprep, but was not successful.
Thanks in advance.

采纳的回答

Walter Roberson
Walter Roberson 2018-4-7
S = fileread('YourFile.txt');
wanted = regexprep(S, {'^\S.*$\n','^$\n'}, {'',''}, 'lineanchors', 'dotexceptnewline');
  3 个评论
Swathi Putchakayala
but i need only the rows and coloums of the above data. But not the whole thing in that document.
Walter Roberson
Walter Roberson 2019-4-10
Perhaps your input does not exactly match the one that I wrote this code for. I designed this code for the case where the unwanted lines all begin with a character that is not whitespace.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by