⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch28_02.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 28] 28.2 Comparing Three Different Versions with diff3 </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:44:42Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch28_01.htm"TITLE="28. Comparing Files"><LINKREL="prev"HREF="ch28_01.htm"TITLE="28.1 Checking Differences with diff "><LINKREL="next"HREF="ch28_03.htm"TITLE="28.3 Context diffs "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch28_01.htm"TITLE="28.1 Checking Differences with diff "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 28.1 Checking Differences with diff "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 28<BR>Comparing Files</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch28_03.htm"TITLE="28.3 Context diffs "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 28.3 Context diffs "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-7961">28.2 Comparing Three Different Versions with diff3 </A></H2><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="diff3">diff3</A><BR></TH><TDVALIGN="TOP"><ACLASS="indexterm"NAME="AUTOID-31068"></A><ACLASS="indexterm"NAME="AUTOID-31070"></A>You can use the <EMCLASS="emphasis">diff3</EM> command to look at differences betweenthree files.(There's also a GNU version on the CD-ROM.)Here are three sample files, repeated from article<ACLASS="xref"HREF="ch28_01.htm#UPT-ART-2680"TITLE="Checking Differences with diff ">28.1</A>:</TD></TR></TABLE><TABLECLASS="informaltable"><THEADCLASS="thead"><TRCLASS="row"VALIGN="TOP"><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">test1</TH><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">test2</TH><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">test3</TH></TR></THEAD><TBODYCLASS="tbody"><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">apples</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">apples</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">oranges</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">oranges</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">oranges</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">walnuts</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">walnuts</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">grapes</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">chestnuts</TD></TR></TBODY></TABLE><PCLASS="para">For each set of differences, <EMCLASS="emphasis">diff3</EM> displays a row of equalsigns (<CODECLASS="literal">====</CODE>) followed by 1, 2, or 3, indicating which file isdifferent; if no number is specified, then all three files differ.Then, using<SPANCLASS="link"><EMCLASS="emphasis">ed</EM>-like notation (<ACLASS="linkend"HREF="ch28_01.htm#UPT-ART-2680"TITLE="Checking Differences with diff ">28.1</A>)</SPAN>,the differences are described foreach file.</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">$ <CODECLASS="userinput"><B>diff3 test1 test2 test3</B></CODE>====31:1c2:1c  apples3:0a====1:3c  walnuts2:3c  grapes3:2,3c  walnuts  chestnuts</PRE></BLOCKQUOTE></P><PCLASS="para">With the output of <EMCLASS="emphasis">diff3</EM>, it is easy to keep track of which fileis which; however, the prescription given is a little harder todecipher.To bring these files into agreement, the first range of text(after <CODECLASS="literal">====3</CODE>) shows that you would have to add <CODECLASS="literal">apples</CODE> at thebeginning of the third file (<CODECLASS="literal">3:0a</CODE>).The second range tells you to change line3 of the second file to line 3 of the first file; and change lines 2and 3 of the third file, effectively dropping the last line.</P><PCLASS="para">The <EMCLASS="emphasis">diff3</EM> command also has a <EMCLASS="emphasis">-e</EM> option for creating anediting script for <EMCLASS="emphasis">ed</EM>.It doesn't work quite the way you mightthink.Basically, it creates a script for building the first file fromthe second and third files.</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">$ <CODECLASS="userinput"><B>diff3 -e test1 test2 test3</B></CODE>3cwalnutschestnuts.1d.wq</PRE></BLOCKQUOTE></P><PCLASS="para">If you reverse the second and third files, a different script is produced:&#13;</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">$ <CODECLASS="userinput"><B>diff3 -e test1 test3 test2</B></CODE>3cgrapes.wq</PRE></BLOCKQUOTE></P><PCLASS="para">As you might guess, this is basically the same output as doinga <EMCLASS="emphasis">diff</EM> on the first and third files.(The only difference in the output is the result of arather errant inconsistency between <EMCLASS="emphasis">diff</EM> and <EMCLASS="emphasis">diff3</EM>.The System V version of <EMCLASS="emphasis">diff3</EM> produces an <EMCLASS="emphasis">ed</EM> script that endswith the commands that save the edited version of the file.The Berkeley <EMCLASS="emphasis">diff3</EM>, and both versions of <EMCLASS="emphasis">diff</EM>, require that yousupply the <CODECLASS="literal">w</CODE> and <CODECLASS="literal">q</CODE>.We show the System V version of <EMCLASS="emphasis">diff3</EM> here.)</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">DD</SPAN> <SPANCLASS="bibliomisc">from <CITECLASS="citetitle">UNIX Text Processing</CITE>, Hayden Books, 1987, Chapter 11</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch28_01.htm"TITLE="28.1 Checking Differences with diff "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 28.1 Checking Differences with diff "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch28_03.htm"TITLE="28.3 Context diffs "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 28.3 Context diffs "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">28.1 Checking Differences with diff </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">28.3 Context diffs </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -