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

📄 ch33_01.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 33] Batch Editing</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:46:45Z"><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="part05.htm"TITLE="V. Text Editing "><LINKREL="prev"HREF="ch32_13.htm"TITLE="32.13 An Absurd Amusement "><LINKREL="next"HREF="ch33_02.htm"TITLE="33.2 Writing Editing Scripts "></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="ch32_13.htm"TITLE="32.13 An Absurd Amusement "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 32.13 An Absurd Amusement "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 33</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch33_02.htm"TITLE="33.2 Writing Editing Scripts "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 33.2 Writing Editing Scripts "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="CHAPTER"><H1CLASS="chapter"><ACLASS="title"NAME="UPT-CHP-33">33. Batch Editing</A></H1><DIVCLASS="htmltoc"><P><B>Contents:</B><BR><ACLASS="sect1"HREF="#UPT-ART-7965"TITLE="33.1 Why Line Editors Aren't Dinosaurs ">Why Line Editors Aren't Dinosaurs </A><BR><ACLASS="sect1"HREF="ch33_02.htm"TITLE="33.2 Writing Editing Scripts ">Writing Editing Scripts </A><BR><ACLASS="sect1"HREF="ch33_03.htm"TITLE="33.3 Line Addressing ">Line Addressing </A><BR><ACLASS="sect1"HREF="ch33_04.htm"TITLE="33.4 Useful ex Commands ">Useful ex Commands </A><BR><ACLASS="sect1"HREF="ch33_05.htm"TITLE="33.5 Running Editing Scripts Within vi ">Running Editing Scripts Within vi </A><BR><ACLASS="sect1"HREF="ch33_06.htm"TITLE="33.6 Change Many Files by Editing Just One ">Change Many Files by Editing Just One </A><BR><ACLASS="sect1"HREF="ch33_07.htm"TITLE="33.7 ed/ex Batch Edits: Avoid Errors When No Match ">ed/ex Batch Edits: Avoid Errors When No Match </A><BR><ACLASS="sect1"HREF="ch33_08.htm"TITLE="33.8 Batch Editing Gotcha: Editors Bomb on Big Files ">Batch Editing Gotcha: Editors Bomb on Big Files </A><BR><ACLASS="sect1"HREF="ch33_09.htm"TITLE="33.9 patch: Generalized Updating of Files that Differ ">patch: Generalized Updating of Files that Differ </A><BR><ACLASS="sect1"HREF="ch33_10.htm"TITLE="33.10 Quick Globals from the Command Line with qsubst ">Quick Globals from the Command Line with qsubst </A><BR><ACLASS="sect1"HREF="ch33_11.htm"TITLE="33.11 Quick Reference: awk ">Quick Reference: awk </A><BR><ACLASS="sect1"HREF="ch33_12.htm"TITLE="33.12 Versions of awk ">Versions of awk </A></P><P></P></DIV><ACLASS="indexterm"NAME="AUTOID-36226"></A><DIVCLASS="sect1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-7965">33.1 Why Line Editors Aren't Dinosaurs </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-36233"></A><ACLASS="indexterm"NAME="AUTOID-36236"></A><ACLASS="indexterm"NAME="UPT-ART-7965-IX-EDITORS-SCRIPTING-LINE-EDITORS"></A><ACLASS="indexterm"NAME="AUTOID-36241"></A><ACLASS="indexterm"NAME="AUTOID-36245"></A><ACLASS="indexterm"NAME="AUTOID-36249"></A>In the &quot;old days,&quot; when programmers worked on printing terminals,editing was done one line at a time. Editors that let you movea cursor around the screen to select text to edit weren't invented,because there weren't any screens to look at text on!</P><PCLASS="para">In these days of even more advanced WYSIWYG (What You See Is WhatYou Get) word processors an editing programs, it's easy for novicesto think of line editors as a bizarre relic. Perhaps they are&nbsp;- butif so, they are a relic of extraordinary power.</P><PCLASS="para">You see, line editors lend themselves to <EMCLASS="emphasis">scripting</EM>-the abilityto write what in effect are editing programs that can be applied overand over to different files. </P><PCLASS="para">When we talk about &quot;batch editing&quot; or scripts, here are some of theprograms you might use:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para"><EMCLASS="emphasis">ed</EM> is the original UNIX line editor.</P></LI><LICLASS="listitem"><PCLASS="para"><EMCLASS="emphasis">ex</EM> supports a superset of <EMCLASS="emphasis">ed</EM> commands; it is widely used from within <EMCLASS="emphasis">vi</EM>, which is the <EMCLASS="emphasis">ex</EM> &quot;visual&quot; or &quot;screen&quot; mode.</P></LI><LICLASS="listitem"><PCLASS="para"><EMCLASS="emphasis">sed</EM> is an editor that can <EMCLASS="emphasis">only</EM> be run with scripts [or byentering a few short commands as command-line arguments -<EMCLASS="emphasis">JP</EM>&nbsp;]; whileit has many similar commands, it has some <SPANCLASS="link">important differences (<ACLASS="linkend"HREF="ch34_01.htm#UPT-ART-7996"TITLE="Two Things You Must Know About sed ">34.1</A>)</SPAN>from <EMCLASS="emphasis">ed</EM> and <EMCLASS="emphasis">ex</EM>.</P></LI><LICLASS="listitem"><PCLASS="para"><SPANCLASS="link"><EMCLASS="emphasis">patch</EM> (<ACLASS="linkend"HREF="ch33_09.htm"TITLE="patch: Generalized Updating of Files that Differ ">33.9</A>)</SPAN>is a specialized editor designed to apply editing scripts createdwith <SPANCLASS="link"><EMCLASS="emphasis">diff</EM> (<ACLASS="linkend"HREF="ch28_01.htm#UPT-ART-2680"TITLE="Checking Differences with diff ">28.1</A>)</SPAN>.You can do this with <EMCLASS="emphasis">ed</EM> or <EMCLASS="emphasis">ex</EM> as well, but <EMCLASS="emphasis">patch</EM> isespecially clever at it.</P></LI></UL><PCLASS="para">Of course, editing is a continuum, and beyond <EMCLASS="emphasis">sed</EM>, you canthink of <SPANCLASS="link"><EMCLASS="emphasis">awk</EM> (<ACLASS="linkend"HREF="ch33_11.htm"TITLE="Quick Reference: awk ">33.11</A>)</SPAN>and <SPANCLASS="link"><EMCLASS="emphasis">perl</EM> (<ACLASS="linkend"HREF="ch37_01.htm#UPT-ART-5560"TITLE="What We Do and Don't Tell You About Perl ">37.1</A>)</SPAN>as even more powerful editing programs.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">TOR</SPAN></P></DIV></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="ch32_13.htm"TITLE="32.13 An Absurd Amusement "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 32.13 An Absurd Amusement "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="ch33_02.htm"TITLE="33.2 Writing Editing Scripts "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 33.2 Writing Editing Scripts "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">32.13 An Absurd Amusement </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">33.2 Writing Editing Scripts </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 + -