This tutorial explains Linux “merge” command, options and its usage with examples.
Usage:
merge [ options ] file1 file2 file3
merge incorporates all changes that lead from file2 to file3 into file1. The result ordinarily goes into file1. merge is useful for combining separate changes to an original. Suppose file2 is the original, and both file1 and file3 are modifications of file2. Then merge combines both changes.
Note
* merge is a very rarely used command.
* When merging files all files must exist.
Here’s the listing of example usage of “merge” command:
To install merge type in terminal .
sudo apt-get install rcs
1. To show conflicts between the files:
sanfoundry-> touch file1 file2 file3 sanfoundry-> cat file2 Hi i am a nice boy I like cricket sanfoundry-> cat file3 Hi i am a boy I like football sanfoundry-> merge file1 file2 file3 merge: warning: conflicts during merge sanfoundry-> cat file1 <<<<<<< file1 ======= Hi i am a boy I like football >>>>>>> file3
A conflict occurs if both file1 and file3 have changes in a common segment of lines. If a conflict is found, merge normally outputs a warning and brackets the conflict with <<<<<<< and >>>>>>> lines.
Example
<<<<<<< file A
lines in file A
=======
lines in file B
>>>>>>> file B
2. For a verbose output(merge -A file1 file2 file3):
Output conflicts using the -A style of diff3, if supported by diff3. This merges all changes leading from file2 to file3 into file1, and generates the most verbose output.
sanfoundry-> merge -A file1 file2 file3 merge: warning: conflicts during merge sanfoundry-> cat file1 <<<<<<< file1 ||||||| file2 Hi i am a nice boy I like cricket ======= Hi i am a boy I like football >>>>>>> file3
3. For lesser detail output than verbose(merge -E file1 file2 file3):
These options specify conflict styles that generate less information than -A.
sanfoundry-> merge -E file1 file2 file3 merge: warning: conflicts during merge sanfoundry-> cat file1 <<<<<<< file1 ======= Hi i am a boy I like football >>>>>>> file3
4. To send results to standard output instead of overwriting file1(merge -e file1 file2 file3):
sanfoundry-> merge -p file1 file2 file3 <<<<<<< file1 ======= Hi i am a boy I like football >>>>>>> file3 merge: warning: conflicts during merge
5. To be quiet and do not warn about conflicts(merge -q file1 file2 file3):
sanfoundry-> merge -q file1 file2 file3
To Print ‘s version number:
sanfoundry-> merge -V file1 file2 file3 RCS version 5.7
6. To lable files(merge -L 1 -L 2 -L 3 file1 file2 file3):
This option may be given up to three times, and specifies labels to be used in place of the corresponding file names in conflict reports. That is, merge -L x -L y -L z a b c generates output that looks like it came from files x, y and z instead of from files a, b and c.
sanfoundry-> merge -L 1 -L 2 -L 3 file1 file2 file3 merge: warning: conflicts during merge sanfoundry-> cat file1 <<<<<<< 1 ======= Hi i am a boy I like football >>>>>>> 3
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.
- Check Information Technology Books
- Check Linux Books
- Apply for Programming Internship
- Practice Programming MCQs