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

📄 _chapter 3.htm

📁 linux、unix初学者的必读书籍 详细讲述了shell编程方法与技巧
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<span class="docEmphasis">northeast        NE     AM Main Jr.      5.1  .94   3   13</span>
<span class="docEmphasis">north            NO     Margot Weber     4.5  .89   5    9</span>
</pre>
<div align="center">
  <center>
<table cellSpacing="0" width="90%" border="1" style="border-collapse: collapse" bordercolor="#111111" cellpadding="5">
  <tr>
    <td>
    <h2 class="docSidebarTitle">EXPLANATION</h2>
    <p class="docText">Prints all lines beginning with an
    <span class="docEmphasis">n.</span> The caret (<span class="docEmphasis">^</span>) 
    is the beginning-of-line anchor.</td>
  </tr>
</table>
  </center>
</div>
<h5 id="ch03list08" class="docExampleTitle">Example 3.8 </h5>
<pre><span class="docEmphStrong">grep '4$' datafile</span>
<span class="docEmphasis">northwest        NW     Charles Main     3.0  .98   3   34</span>
</pre>
<div align="center">
  <center>
<table cellSpacing="0" width="90%" border="1" style="border-collapse: collapse" bordercolor="#111111" cellpadding="5">
  <tr>
    <td>
    <h2 class="docSidebarTitle">EXPLANATION</h2>
    <p class="docText">Prints all lines ending with a <span class="docEmphasis">
    4.</span> The dollar sign (<span class="docEmphasis">$</span>) is the end of 
    line anchor.</td>
  </tr>
</table>
  </center>
</div>
<h5 id="ch03list09" class="docExampleTitle">Example 3.9 </h5>
<pre><span class="docEmphStrong">grep TB Savage datafile</span>
<span class="docEmphasis">grep: Savage: No such file or directory</span>
<span class="docEmphasis">datafile:eastern   EA TB Savage           4.4  .84   5   20</span>
</pre>
<div align="center">
  <center>
<table cellSpacing="0" width="90%" border="1" style="border-collapse: collapse" bordercolor="#111111" cellpadding="5">
  <tr>
    <td>
    <h2 class="docSidebarTitle">EXPLANATION</h2>
    <p class="docText">Since the first argument is the pattern and all of the 
    remaining arguments are filenames, <span class="docEmphasis">grep</span> 
    will search for <span class="docEmphasis">TB</span> in a file called
    <span class="docEmphasis">Savage</span> and a file called
    <span class="docEmphasis">datafile.</span> To search for
    <span class="docEmphasis">TB Savage,</span> see the next example.</td>
  </tr>
</table>
  </center>
</div>
<h5 id="ch03list10" class="docExampleTitle">Example 3.10 </h5>
<pre><span class="docEmphStrong">grep 'TB Savage' datafile</span>
<span class="docEmphasis">eastern          EA     TB Savage         4.4  .84    5   20</span>
</pre>
<div align="center">
  <center>
<table cellSpacing="0" width="90%" border="1" style="border-collapse: collapse" bordercolor="#111111" cellpadding="5">
  <tr>
    <td>
    <h2 class="docSidebarTitle">EXPLANATION</h2>
    <p class="docText">Prints all lines containing the pattern
    <span class="docEmphasis">TB Savage.</span> Without quotes (in this example, 
    either single or double quotes will do), the whitespace between
    <span class="docEmphasis">TB</span> and <span class="docEmphasis">Savage</span> 
    would cause <span class="docEmphasis">grep</span> to search for
    <span class="docEmphasis">TB</span> in a file called
    <span class="docEmphasis">Savage</span> and a file called
    <span class="docEmphasis">datafile,</span> as in the previous example.</td>
  </tr>
</table>
  </center>
</div>
<pre>% <span class="docEmphStrong">cat datafile</span>
<span class="docEmphasis">northwest          NW    Charles Main       3.0    .98    3    34</span>
<span class="docEmphasis">western            WE    Sharon Gray        53     .97    5    23</span>
<span class="docEmphasis">southwest          SW    Lewis Dalsass      2.7    .8     2    18</span>
<span class="docEmphasis">southern           SO    Suan Chin          5.1    .95    4    15</span>
<span class="docEmphasis">southeast          SE    Patricia Hemenway  4.0    .7     4    17</span>
<span class="docEmphasis">eastern            EA    TB Savage          4.4    .84    5    20</span>
<span class="docEmphasis">northeast          NE    AM Main Jr.        5.1    .94    3    13</span>
<span class="docEmphasis">north              NO    Margot Weber       4.5    .89    5     9</span>
<span class="docEmphasis">central            CT    Ann Stephens       5.7    .94    5    13</span>
</pre>
<h5 id="ch03list11" class="docExampleTitle">Example 3.11 </h5>
<pre><span class="docEmphStrong">grep '5\..' datafile</span>
<span class="docEmphasis">western          WE     Sharon Gray       5.3  .97   5   23</span>
<span class="docEmphasis">southern         SO     Suan Chin         5.1  .95   4   15</span>
<span class="docEmphasis">northeast        NE     AM Main Jr.       5.1  .94   3   13</span>
<span class="docEmphasis">central          CT     Ann Stephens      5.7  .94   5   13</span>
</pre>
<div align="center">
  <center>
<table cellSpacing="0" width="90%" border="1" style="border-collapse: collapse" bordercolor="#111111" cellpadding="5">
  <tr>
    <td>
    <h2 class="docSidebarTitle">EXPLANATION</h2>
    <p class="docText">Prints a line containing the number
    <span class="docEmphasis">5,</span> followed by a literal period and any 
    single character. The &quot;dot&quot; metacharacter represents a single character, 
    unless it is escaped with a backslash. When escaped, the character is no 
    longer a special metacharacter, but represents itself, a literal period.</td>
  </tr>
</table>
  </center>
</div>
<h5 id="ch03list12" class="docExampleTitle">Example 3.12 </h5>
<pre><span class="docEmphStrong">grep '\.5' datafile</span>
<span class="docEmphasis">north            NO     Margot Weber     4.5  .89   5   9</span>
</pre>
<div align="center">
  <center>
<table cellSpacing="0" width="90%" border="1" style="border-collapse: collapse" bordercolor="#111111" cellpadding="5">
  <tr>
    <td>
    <h2 class="docSidebarTitle">EXPLANATION</h2>
    <p class="docText">Prints any line containing the expression
    <span class="docEmphasis">.5.</span></td>
  </tr>
</table>
  </center>
</div>
<h5 id="ch03list13" class="docExampleTitle">Example 3.13 </h5>
<pre><span class="docEmphStrong">grep '^[we]' datafile</span>
<span class="docEmphasis">western          WE     Sharon Gray     5.3  .97   5   23</span>
<span class="docEmphasis">eastern          EA     TB Savage       4.4  .84   5   20</span>
</pre>
<div align="center">
  <center>
<table cellSpacing="0" width="90%" border="1" style="border-collapse: collapse" bordercolor="#111111" cellpadding="5">
  <tr>
    <td>
    <h2 class="docSidebarTitle">EXPLANATION</h2>
    <p class="docText">Prints lines beginning with either a
    <span class="docEmphasis">w</span> or an <span class="docEmphasis">e.</span> 
    The caret (<span class="docEmphasis">^</span>) is the beginning-of-line 
    anchor, and either one of the characters in the brackets will be matched.</td>
  </tr>
</table>
  </center>
</div>
<h5 id="ch03list14" class="docExampleTitle">Example 3.14 </h5>
<pre><span class="docEmphStrong">grep '[^0-9]' datafile</span>
<span class="docEmphasis">northwest        NW    Charles Main          3.0  .98  3   34</span>
<span class="docEmphasis">western          WE    Sharon Gray           5.3  .97  5   23</span>
<span class="docEmphasis">southwest        SW    Lewis Dalsass         2.7  .8   2   18</span>
<span class="docEmphasis">southern         SO    Suan Chin             5.1  .95  4   15</span>
<span class="docEmphasis">southeast        SE    Patricia Hemenway     4.0  .7   4   17</span>
<span class="docEmphasis">eastern          EA    TB Savage             4.4  .84  5   20</span>
<span class="docEmphasis">northeast        NE    AM Main Jr.           5.1  .94  3   13</span>
<span class="docEmphasis">north            NO    Margot Weber          4.5  .89  5   9</span>
<span class="docEmphasis">central          CT    Ann Stephens          5.7  .94  5   13</span>
</pre>
<div align="center">
  <center>
<table cellSpacing="0" width="90%" border="1" style="border-collapse: collapse" bordercolor="#111111" cellpadding="5">
  <tr>
    <td>
    <h2 class="docSidebarTitle">EXPLANATION</h2>
    <p class="docText">Prints all lines containing one non-digit. Because all 
    lines have at least one non-digit, all lines are printed. (See the
    <span class="docEmphasis">杤</span> option.)</td>
  </tr>
</table>
  </center>
</div>
<h5 id="ch03list15" class="docExampleTitle">Example 3.15 </h5>
<pre><span class="docEmphStrong">grep '[A-Z][A-Z] [A-Z]' datafile</span>
<span class="docEmphasis">eastern          EA     TB Savage       4.4  .84   5   20</span>
<span class="docEmphasis">northeast        NE     AM Main Jr.     5.1  .94   3   13</span>
</pre>
<div align="center">
  <center>
<table cellSpacing="0" width="90%" border="1" style="border-collapse: collapse" bordercolor="#111111" cellpadding="5">
  <tr>
    <td>
    <h2 class="docSidebarTitle">EXPLANATION</h2>
    <p class="docText">Prints all lines containing two capital letters followed 
    by a space and a capital letter, e.g., <span class="docEmphasis">TB Savage</span> 
    and <span class="docEmphasis">AM Main.</span></td>
  </tr>
</table>
  </center>
</div>
<h5 id="ch03list16" class="docExampleTitle">Example 3.16 </h5>
<pre><span class="docEmphStrong">grep 'ss* ' datafile</span>
<span class="docEmphasis">northwest        NW     Charles Main     3.0  .98   3   34</span>
<span class="docEmphasis">southwest        SW     Lewis Dalsass    2.7  .8    2   18</span>
</pre>
<div align="center">
  <center>
<table cellSpacing="0" width="90%" border="1" style="border-collapse: collapse" bordercolor="#111111" cellpadding="5">
  <tr>
    <td>
    <h2 class="docSidebarTitle">EXPLANATION</h2>
    <p class="docText">Prints all lines containing an <span class="docEmphasis">
    s</span> followed by zero or more consecutive occurrences of the letter
    <span class="docEmphasis">s</span> and a space. Finds
    <span class="docEmphasis">Charles</span> and <span class="docEmphasis">
    Dalsass.</span></td>
  </tr>
</table>
  </center>
</div>
<pre>% <span class="docEmphStrong">cat datafile</span>
<span class="docEmphasis">northwest           NW     Charles Main       3.0  .98  3    34</span>
<span class="docEmphasis">western             WE     Sharon Gray        53   .97  5    23</span>
<span class="docEmphasis">southwest           SW     Lewis Dalsass      2.7  .8   2    18</span>
<span class="docEmphasis">southern            SO     Suan Chin          5.1  .95  4    15</span>
<span class="docEmphasis">southeast           SE     Patricia Hemenway  4.0  .7   4    17</span>
<span class="docEmphasis">eastern             EA     TB Savage          4.4  .84  5    20</span>
<span class="docEmphasis">northeast           NE     AM Main Jr.        5.1  .94  3    13</span>
<span class="docEmphasis">north               NO     Margot Weber       4.5  .89  5     9</span>
<span class="docEmphasis">central             CT     Ann Stephens       5.7  .94  5    13</span>
</pre>
<h5 id="ch03list17" class="docExampleTitle">Example 3.17 </h5>
<pre><span class="docEmphStrong">grep '[a-z]\{9\}' datafile</span>
<span class="docEmphasis">northwest        NW    Charles Main      3.0  .98   3   34</span>
<span class="docEmphasis">southwest        SW    Lewis Dalsass     2.7  .8    2   18</span>
<span class="docEmphasis">southeast        SE    Patricia Hemenway 4.0  .7    4   17</span>
<span class="docEmphasis">northeast        NE    AM Main Jr.       5.1  .94   3   13</span>
</pre>
<div align="center">
  <center>
<table cellSpacing="0" width="90%" border="1" style="border-collapse: collapse" bordercolor="#111111" cellpadding="5">
  <tr>
    <td>
    <h2 class="docSidebarTitle">EXPLANATION</h2>
    <p class="docText">Prints all lines where there are at least nine 
    consecutive lowercase letters, for example<span class="docEmphasis">, 
    northwest, southwest, southeast,</span> and <span class="docEmphasis">
    northeast.</span></td>
  </tr>
</table>
  </center>
</div>
<h5 id="ch03list18" class="docExampleTitle">Example 3.18 </h5>

⌨️ 快捷键说明

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