Clear Filters
Clear Filters

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

2 views (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Apr 2018
S = fileread('YourFile.txt');
wanted = regexprep(S, {'^\S.*$\n','^$\n'}, {'',''}, 'lineanchors', 'dotexceptnewline');
  3 Comments
Swathi Putchakayala
Swathi Putchakayala on 10 Apr 2019
but i need only the rows and coloums of the above data. But not the whole thing in that document.
Walter Roberson
Walter Roberson on 10 Apr 2019
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!