Copy and paste all lines from the first text file to another text file after certain line numbers
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Birsen Ayaz-Maierhafer
 el 22 de Dic. de 2022
  
    
    
    
    
    Comentada: Mathieu NOE
      
 el 22 de Dic. de 2022
            Hi,
I would like to copy and paste the values from the first txt file (Al.txt) to another text file (TestFile1.txt) after line 6. It should look like the TestFileWithAl.txt. It is copy and paste the values without loosing the rest of the information in TestFile1.txt
I wrote the follwing code The following code does not tell which line to paste in TestFile1.txt.  How will I tell copy and past after line 6?
tmp = readlines('Al.txt');
writelines(tmp(1:end), 'TestFile1.txt')
Thank you for your help
0 comentarios
Respuesta aceptada
  Mathieu NOE
      
 el 22 de Dic. de 2022
        hello 
try this 
simply split and concatenate the strings then save the result 
for me  with writematrix  as I run R2020, with writelines if you are equipped with R2022
tmp1 = readlines('Al.txt');
tmp1(strcmp(tmp1,"")) = []; % removes empty lines (needed ?)
tmp2 = readlines('TestFile1.txt');
line_insertion = 6; % define at which line of A1 text you insert TestFile1 text
out = [tmp2(1:line_insertion-1); tmp1; tmp2(line_insertion+1:end)];
writelines(out, 'Output.txt')
% writematrix(out, 'Output.txt') % before R2022
2 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Characters and Strings en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

