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.
0 个评论
采纳的回答
Walter Roberson
2018-4-7
S = fileread('YourFile.txt');
wanted = regexprep(S, {'^\S.*$\n','^$\n'}, {'',''}, 'lineanchors', 'dotexceptnewline');
3 个评论
Swathi Putchakayala
2019-4-10
but i need only the rows and coloums of the above data. But not the whole thing in that document.
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 Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!