It's called "paging output" or (somewhat erroneously) "pagination" ā¦
ā¦ and man
does it by invoking your preferred pager shell command, named by your PAGER
environment variable, upon the output of whatever pipeline was used to generate the output form of the manual page. It falls back to a default if you haven't specified a pager command. On early Unices the default pager program, that man
invokes as the default pager command with known hardwired options, was pg
. On your system it is probably more
or less
. Some man
commands look at other environment variables for pager commands, as well.
You do it by doing what man
is doing: pipe the output of what you want to see into the standard input of a pager program.
You should get yourself a good book on Unix. There are a fair few that explain this, which is a very basic feature of the system. A simple Google Books search for pager unix more
by me today turned up over a hundred books that discuss this. (I stopped counting at a hundred.)
You don't need patch
for this; it's for extracting changes and sending them on without the unchanged part of the file.
The tool for merging two versions of a file is merge
, but as @vonbrand
wrote, you need the "base" file from which your two versions diverged. To do a merge without it, use diff
like this:
diff -DVERSION1 file1.xml file2.xml > merged.xml
It will enclose each set of changes in C-style #ifdef
/#ifndef
"preprocessor" commands, like this:
#ifdef VERSION1
<stuff added to file1.xml>
#endif
...
#ifndef VERSION1
<stuff added to file2.xml>
#endif
If a line or region differs between the two files, you'll get a "conflict", which looks like this:
#ifndef VERSION1
<version 1>
#else /* VERSION1 */
<version 2>
#endif /* VERSION1 */
So save the output in a file, and open it in an editor. Search for any places where #else
comes up, and resolve them manually. Then save the file and run it through grep -v
to get rid of the remaining #if(n)def
and #endif
lines:
grep -v '^#if' merged.xml | grep -v '^#endif' > clean.xml
In the future, save the original version of the file. merge
can give you much better results with the help of the extra information. (But be careful: merge
edits one of the files in-place, unless you use -p
. Read the manual).
Best Answer
-u by itself outputs results in "unified" format the number just changes the number of neighboring lines included as context.