Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenating multiple text files into a single file in Bash

Tags:

bash

shell

What is the quickest and most pragmatic way to combine all *.txt file in a directory into one large text file?

Currently I'm using windows with cygwin so I have access to BASH.

Windows shell command would be nice too but I doubt there is one.

like image 462
Yada Avatar asked Jan 27 '10 22:01

Yada


People also ask

How do I combine multiple text files into one in Linux?

To join two or more text files on the Linux command-line, you can use the cat command. The cat (short for “concatenate”) command is one of the most commonly used commands in Linux as well as other UNIX-like operating systems, used to concatenate files and print on the standard output.

How do I combine multiple text files into one?

Open the two files you want to merge. Select all text (Command+A/Ctrl+A) from one document, then paste it into the new document (Command+V/Ctrl+V). Repeat steps for the second document. This will finish combining the text of both documents into one.

How do I merge files in shell script?

Appending content to an existing file To append content after you merge multiple files in Linux to another file, use double redirection operator. (>>) along with cat command. Rather than overwriting the contents of the file, this command appends the content at the end of the file.


1 Answers

This appends the output to all.txt

cat *.txt >> all.txt 

This overwrites all.txt

cat *.txt > all.txt 
like image 77
Robert Greiner Avatar answered Sep 30 '22 18:09

Robert Greiner