如何将两个文件合并为一个文本文件? [英] How to merge two files into one text file?

查看:61
本文介绍了如何将两个文件合并为一个文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将两个文本输出文件合并为一个文本文件.

I am trying to merge two text output file into one text file .

文件1:

fin=fopen('d://box1.txt','wt');
fprintf(fin,'   Hello \n');

文件2:

fin=fopen('d://box2.txt','wt');
fprintf(fin,'welcome \n');

有什么想法吗?

推荐答案

我认为没有Matlab可以轻松地做到这一点.但是您可以使用系统命令:

I don't think there is a matlab way of doing it easily. But you can use system commands:

Windows:

system(type a.txt b.txt >ab.txt)

Linux:

system(cat a.txt b.txt >ab.txt)

如果文件中的路径不在当前目录中,请不要忘记将其放入文件中! 这有效:

Dont forget to put the path in the files if they are not in your current directory! This works:

fin=fopen('D:\box1.txt','wt');
fprintf(fin,'   Hello \n');
fclose(fin)

fin=fopen('D:\box2.txt','wt');
fprintf(fin,'welcome \n');
fclose(fin)

system('type D:\box1.txt D:\box2.txt >E:\box12.txt')

这篇关于如何将两个文件合并为一个文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆