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

📄 ch33_10.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 33] 33.10 Quick Globals from the Command Line with qsubst </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:57Z"><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="ch33_01.htm"TITLE="33. Batch Editing"><LINKREL="prev"HREF="ch33_09.htm"TITLE="33.9 patch: Generalized Updating of Files that Differ "><LINKREL="next"HREF="ch33_11.htm"TITLE="33.11 Quick Reference: awk "></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="ch33_09.htm"TITLE="33.9 patch: Generalized Updating of Files that Differ "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 33.9 patch: Generalized Updating of Files that Differ "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 33<BR>Batch Editing</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch33_11.htm"TITLE="33.11 Quick Reference: awk "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 33.11 Quick Reference: awk "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-9012">33.10 Quick Globals from the Command Line with qsubst </A></H2><PCLASS="para">Users at our office frequently have to make global changes across multiple files.<ACLASS="indexterm"NAME="AUTOID-37031"></A><ACLASS="indexterm"NAME="AUTOID-37033"></A><ACLASS="indexterm"NAME="AUTOID-37036"></A>For that purposewe encourage them to use <SPANCLASS="link"><EMCLASS="emphasis">sed</EM> (<ACLASS="linkend"HREF="ch34_24.htm"TITLE="Quick Reference: sed ">34.24</A>)</SPAN>;but <EMCLASS="emphasis">sed</EM> syntaxis tricky for new users (or even some experienced users!).</P><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="qsubst">qsubst</A><BR></TH><TDVALIGN="TOP">As an alternative, try the <EMCLASS="emphasis">qsubst</EM> program, available onour CD-ROM.<EMCLASS="emphasis">qsubst</EM>is a simple query-replace program that anyone can use.Forexample, to change the string &quot;Unix&quot; into &quot;UNIX&quot; in the files<EMCLASS="emphasis">ch01</EM> and <EMCLASS="emphasis">ch02</EM>, you can do:</TD></TR></TABLE><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>qsubst Unix UNIX ch01 ch02</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">You'll be prompted with each line to be changed, in context.That is, the line containing the string will be surrounded by both the previous and the next lines in the file.The string to be changed is underlined:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">Unlike emacs, vi is available on every \o'U_'\o'n_'\o'i_'\o'x_' system.So you canthink of vi as the</PRE></BLOCKQUOTE></P><PCLASS="para">To approve the change, press the space bar.You'll then beprompted with the next occurrence in the file.To refuse thechange, press <CODECLASS="literal">n</CODE> to go on to the next occurrence of the string.You can also use the exclamation point (!) to approve this change andall future changes in this file, and CTRL-g to reject this changeand all future changes.  </P><PCLASS="para">You can also have <EMCLASS="emphasis">qsubst</EM> replace all occurrences withoutprompting, using the <EMCLASS="emphasis">-noask</EM> command-line option:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>qsubst Unix UNIX -noask ch01 ch02</B></CODE>(file: ch01)(file: ch02)</PRE></BLOCKQUOTE></P><PCLASS="para">Both files are edited without prompting.</P><PCLASS="para"><EMCLASS="emphasis">qsubst</EM> is clearly not as powerful as <EMCLASS="emphasis">sed</EM>.It doesn'tunderstand regular expressions: you can only use <EMCLASS="emphasis">qsubst</EM> to replacesimple strings.But <EMCLASS="emphasis">qsubst</EM> is clearly a useful tool for users who justwant to make a simple global change without learning <EMCLASS="emphasis">sed</EM>.</P><PCLASS="para">One word of warning about <EMCLASS="emphasis">qsubst</EM>: if you interrupt <EMCLASS="emphasis">qsubst</EM>midstream (e.g., using CTRL-c), your <EMCLASS="emphasis">stty</EM> settings are likelyto be garbled.If this happens, try the tips in article<ACLASS="xref"HREF="ch42_04.htm"TITLE="Checklist for Resetting a Messed Up Terminal ">42.4</A>to get your<EMCLASS="emphasis">stty</EM> settings correct again.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">LM</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="ch33_09.htm"TITLE="33.9 patch: Generalized Updating of Files that Differ "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 33.9 patch: Generalized Updating of Files that Differ "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_11.htm"TITLE="33.11 Quick Reference: awk "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 33.11 Quick Reference: awk "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">33.9 patch: Generalized Updating of Files that Differ </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.11 Quick Reference: awk </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 + -