Often need arises to merge text files. Recently even I encounter similar situation where I had to merge the two JMeter csv result file for some analysis. It took a little while to figure it out. This can easily be done using
cat and redirection operator (
> OR >>). This command is handy and saves time.
cat file1.txt file2.txt > mergedFile.txt
The above command can be used to merge multiple files into single file by just putting the file names before the indirection operator. e.g.
cat file1.txt file2.txt file3.txt file4.txt > mergedFile.txt
This was simple, isn’t it? Sometimes people avoid using the extra file for merging and put the merged content in either of the source files. This can be done as following.
cat file1.txt >> file2.txt
Basically we are appending the content of file1.txt to file2.txt.