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

2 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Abr. de 2018
S = fileread('YourFile.txt');
wanted = regexprep(S, {'^\S.*$\n','^$\n'}, {'',''}, 'lineanchors', 'dotexceptnewline');
  3 comentarios
Swathi Putchakayala
Swathi Putchakayala el 10 de Abr. de 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 el 10 de Abr. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by