Merging Two Files

Question: Please tell me how to merge two files into a transaction file
Rashid Aga

Answer: There are two things that need to be done to merge two files. First you need to get the content of both files into one file and second you need to get the records into the right order.

Exactly how you perform these tasks depends on the operating system that you are using.

With DOS, any version of Windows, or OS/2 you can use the following commands to do this:

 copy file1.txt newfile.txt
copy newfile.txt + file2.txt
sort | newfile.txt

The flags/switches you can add here (immediately after the word 'sort') include /r to sort in reverse order and /+number to specify the column to sort on.

With Linux (or any other UNIX variant) you can perform both of the steps in one go using the following command:

 cat file1 file2 > newfile | sort

There are a couple of flags/switches you can use with this. Adding -r will sort in reverse order while if you are sorting numerical data you need to include -n.

 

This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow
Donate