How to join .txt-files without importing?

Is it possible to write a code, telling MMA to join 2 (or even more) .txt-files without importing them?




Something like cat then?
– J. M.♦
Apr 7 at 9:50



@J.M. hmm, don’t know what cat means, except a pet…
– Kay
Apr 7 at 10:32



cat is Unix-style command line command
– Rom38
Apr 7 at 10:34



sounds like this is what I mean, as I can force MMA to rename files, I thought this joining might also work somehow. Looks like there is no such command, isn’t there?
– Kay
Apr 7 at 10:36



cat: Run: Could be a goer?
– Quantum_Oli
Apr 7 at 10:44


2 Answers


Lets say you have two files 1.txt and 2.txt. You open your terminal, go to the folder and type

cat 1.txt 2.txt > new.txt

It will give you a new file new.txt combining the content of 1.txt and 2.txt

But this is not an answer for mathematica community. Lets do the same thing with mathematica.

First I shall create several files.

Do[Export[ToString[i] <> “.txt”, {Join[ConstantArray[“blah”, i], {“\n”}]}, “Table”], {i, 7}]

Now I have 7 files to combine. I am going to create the bash command for cat and then Run it.

com = “cat “;
Do[com = com <> ToString[i] <> “.txt “, {i, 7}]
com = com <> ” > out.txt”

Now you have a file out.txt will everything.



This kind of still isn’t an answer for the MMA community and cat is platform specific.
Apr 7 at 22:08



I agree @LLlAMnYP, but this is the best I can do with MMA without importing the file 😐 .
– Sumit
Apr 9 at 11:26

Run[“cat file1.txt file2.txt > newfile.txt”]

But be sure to set your working directory to the folder with the files in first:

SetDirectory[“~/Desktop/Text Cat”]