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

📄 ch26_10.htm

📁 the unix power tools
💻 HTM
📖 第 1 页 / 共 2 页
字号:
ROWSPAN="1"COLSPAN="1">Same, followed by two lowercase letters (e.g., <EMCLASS="emphasis">troff</EM> requests).</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">^\.[a-z]\{2\}</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Same as previous, <EMCLASS="emphasis">grep</EM> or <EMCLASS="emphasis">sed</EM> only.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">^[^.]</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Any line that doesn't begin with a <CODECLASS="literal">.</CODE> (dot).</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">bugs*</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><CODECLASS="literal">bug</CODE>, <CODECLASS="literal">bugs</CODE>, <CODECLASS="literal">bugss</CODE>, etc.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">&quot;word&quot;</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">A word in quotes.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">&quot;*word&quot;*</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">A word, with or without quotes.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">[A-Z][A-Z]*</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">One or more uppercase letters.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">[A-Z]+</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Same, <EMCLASS="emphasis">egrep</EM> or <EMCLASS="emphasis">awk</EM> only.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">[A-Z].*</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">An uppercase letter, followed by zero or more characters.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">[A-Z]*</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Zero or more uppercase letters.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">[a-zA-Z]</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Any letter.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">[^0-9A-Za-z]</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Any symbol (not a letter or a number).</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">[567]</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">One of the numbers <CODECLASS="literal">5</CODE>, <CODECLASS="literal">6</CODE>, or <CODECLASS="literal">7</CODE>.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><EMCLASS="emphasis">egrep or awk pattern:</EM></TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"></TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">five|six|seven</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">One of the words <CODECLASS="literal">five</CODE>, <CODECLASS="literal">six</CODE>, or <CODECLASS="literal">seven</CODE>.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">80[23]?86</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">One of the numbers <CODECLASS="literal">8086</CODE>, <CODECLASS="literal">80286</CODE>, or <CODECLASS="literal">80386</CODE>.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">compan(y|ies)</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">One of the words <CODECLASS="literal">company</CODE> or <CODECLASS="literal">companies</CODE>.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><EMCLASS="emphasis">ex or vi pattern:</EM></TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"></TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">\&lt;the</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Words like <CODECLASS="literal">theater</CODE> or <CODECLASS="literal">the</CODE>.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">the\&gt;</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Words like <CODECLASS="literal">breathe</CODE> or <CODECLASS="literal">the</CODE>.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">\&lt;the\&gt;</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">The word <CODECLASS="literal">the</CODE>.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><EMCLASS="emphasis">sed or grep pattern:</EM></TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"></TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">0\{5,\}</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Five or more zeros in a row.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">[0-9]\{3\}-[0-9]\{2\}-[0-9]\{4\}</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">US social security number (<CODECLASS="replaceable"><I>nnn</I></CODE><CODECLASS="literal">-</CODE><CODECLASS="replaceable"><I>nn</I></CODE><CODECLASS="literal">-</CODE><CODECLASS="replaceable"><I>nnnn</I></CODE>).</TD></TR></TBODY></TABLE></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-2540-SECT-1.2">26.10.2 Examples of Searching and Replacing </A></H3><PCLASS="para">The following examples show the metacharactersavailable to <EMCLASS="emphasis">sed</EM> or <EMCLASS="emphasis">ex</EM>.(<EMCLASS="emphasis">ex</EM>&nbsp;commands begin with a colon.)A space is marked by <IMGSRC="../chars/squ.gif"ALT=" ">; a TAB is marked by&nbsp;<CODECLASS="replaceable"><I>tab</I></CODE>.</P><TABLECLASS="table"><CAPTIONCLASS="table"><ACLASS="title"NAME="UPT-ART-2540-TAB-3">Table 26.9: Search and Replace Commands</A></CAPTION><THEADCLASS="thead"><TRCLASS="row"VALIGN="TOP"><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">Command</TH><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">Result</TH></TR></THEAD><TBODYCLASS="tbody"><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">s/.*/( &amp; )/</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Redo the entire line, but add parentheses.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">s/.*/mv &amp; &amp;.old/</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Change a wordlist into <EMCLASS="emphasis">mv</EM> commands.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">/^$/d</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Delete blank lines.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:g/^$/d</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><EMCLASS="emphasis">ex</EM> version of previous.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">/^[<IMGSRC="../chars/squ.gif"ALT=" "><CODECLASS="replaceable"><I>tab</I></CODE>]*$/d</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Delete blank lines, plus lines containing only spaces or TABs.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:g/^[<IMGSRC="../chars/squ.gif"ALT=" "><CODECLASS="replaceable"><I>tab</I></CODE>]*$/d</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><EMCLASS="emphasis">ex</EM> version of previous.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">s/<IMGSRC="../chars/squ.gif"ALT=" "><IMGSRC="../chars/squ.gif"ALT=" ">*/<IMGSRC="../chars/squ.gif"ALT=" ">/g</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Turn one or more spaces into one space.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:%s/<IMGSRC="../chars/squ.gif"ALT=" "><IMGSRC="../chars/squ.gif"ALT=" ">*/<IMGSRC="../chars/squ.gif"ALT=" ">/g</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><EMCLASS="emphasis">ex</EM> version of previous.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:s/[0-9]/Item &amp;:/</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Turn a number into an item label (on the current line).</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:s</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Repeat the substitution on the first occurrence.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:&amp;</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Same.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:sg</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Same, but for all occurrences on the line.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:&amp;g</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Same.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:%&amp;g</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Repeat the substitution globally.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:.,$s/Fortran/\U&amp;/g</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Change word to uppercase, on current line to last line.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:%s/.*/\L&amp;/</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Lowercase entire file.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:s/\&lt;./\u&amp;/g</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Uppercase first letter of each word on current line (useful for titles).</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:%s/yes/No/g</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Globally change a word to <CODECLASS="literal">No</CODE>.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">:%s/Yes/~/g</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Globally change a different word to <CODECLASS="literal">No</CODE>(previous replacement).</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">s/die or do/do or die/</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Transpose words.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">s/\([Dd]ie\) or \([Dd]o\)/\2 or \1/</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Transpose, using hold buffers to preserve case.</TD></TR></TBODY></TABLE><ACLASS="indexterm"NAME="AUTOID-29898"></A><ACLASS="indexterm"NAME="AUTOID-29899"></A></DIV><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">DG</SPAN> <SPANCLASS="bibliomisc">from O'Reilly &amp; Associates' <CITECLASS="citetitle">UNIX in a Nutshell (SVR4/Solaris)</CITE></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="ch26_09.htm"TITLE="26.9 Valid Metacharacters for Different UNIX Programs "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 26.9 Valid Metacharacters for Different UNIX Programs "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="CHAPTER"HREF="ch27_01.htm"TITLE="27. Searching Through Files"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 27. Searching Through Files"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">26.9 Valid Metacharacters for Different UNIX Programs </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">27. Searching Through Files</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 + -