Sunday, March 27, 2011

Combine Multiple Text Files in Unix

To combine multiple text files in Unix we need to use the “cat” command.
Syntax: cat filename1 filename2 filename3 >> newfilename

Example: cat a.txt b.txt >> c.txt

In the above example we are combining the contents of the 2 text files in to a third text file. The new file “c.txt” contains the contents of “a.txt” and then the contents “b.txt”.

If the command “cat b.txt a.txt >> c.txt” is used then the new file contains the contents of “b.txt” first and then the contents of “a.txt”.

We can combine any number of text files to a single file. All we need to do is to specify the file names before the “>>” symbol which is the output redirection operator in Unix.

No comments:

Post a Comment