📄 unx06.htm
字号:
pax:pages for more information on how to run PAX,
pax:TAR, and CPIO.
pax:
pax:program that gives the functionality of pax, tar,
pax:and cpio. It supports both the DOS filesystem
pax:and the raw "tape on a disk" system used by most
pax:micro UNIX systems. This will allow for easy
pax:transfer of files to and from UNIX systems. It
pax:also support multiple volumes. Floppy density
pax:for raw UNIX type read/writes can be specified on
pax:the command line.
pax:
pax:The source will eventually be posted to one of
pax:the source groups.
pax:
pax:Be sure to use a blocking factor of 20 with
pax:pax-as-tar and B with pax-as-cpio for best
pax:performance.
cron:level (thus killing cron), and then re-enter
cron:multi-user run level, when a new cron is started;
cron:
cron:The proper way to install a new version of a
cron:crontab (for root, or for any other user) is to
cron:issue the command "crontab new.jobs", or "cat
cron:new.jobs | crontab", or if in 'vi' with a new
cron:version of the commands, "w ! crontab". I find it
cron:easy to type "vi /tmp/tbl", then ":0 r !crontab
cron:-l" to read the existing crontab into the vi
cron:buffer, then edit, then type ":w !crontab", or
cron:"!crontab %" to replace the existing crontab with
cron:what I see on vi's screen.</PRE>
<P>Note that blank lines are considered to be lines that do not match the given regular expression.
<BR></P>
<P>The following example is quite interesting. It lists every line that has r.*t in it and of course it matches the longest possible string in each line. First, let's see exactly how the strings are matched. The matching strings in the listing are
highlighted in italics so that you can see what grep actually matches:
<BR></P>
<PRE>$ grep 'r.*t' pax cron
pax:This is an announcement fo<I>r t</I>he MS-DOS version of
pax:PAX version 2. See the README file and the man
pax:pages for more information on how to run PAX,
pax:Fo<I>r those of you who don't</I> know, pax is a 3 in 1
pax:program that gives the functionality of pax, tar,
pax:and cpio. It suppo<I>rts both the DOS filesyst</I>em
pax:and the raw "tape on a disk" system used by most
pax:mic<I>ro UNIX systems. T</I>his will allow for easy
pax:transfer of files to and from UNIX systems. It
pax:also support multiple volumes. Floppy density
pax:fo<I>r raw UNIX type read/writ</I>es can be specified on
pax:The source will eventually be posted to one of
pax:Be sure to use a blocking factor of 20 with
pax:pax-as-tar and B with pax-as-cpio for best
cron:In SCO Xenix 2.3, o<I>r SCO UNIX, you can edit</I> a
cron:crontab file to your heart's content, but it will
cron:not be re-read, and your changes will not take
cron:level (thus killing c<I>ron), and then re-ent</I>er
cron:multi-user run level, when a new cron is started;
cron:or until you do a reboot.
cron:The prope<I>r way to inst</I>all a new version of a
cron:crontab (for root, or for any other user) is to
cron:issue the command "c<I>rontab new.jobs", or "cat</I>
cron:new.jobs | c<I>ront</I>ab", or if in 'vi' with a new
cron:version of the commands, "w ! crontab". I find it
cron:easy to type "vi /tmp/tbl", then ":0 <I>r !cront</I>ab
cron:-l" to read the existing crontab into the vi
cron:buffer, then edit, then type ":w !crontab", or
cron:"!crontab %" to replace the existing crontab with</PRE>
<P>You can obtain for free a version of grep that highlights the matched string, but the standard version of grep simply shows the line that contains the match.
<BR></P>
<P>If you are thinking that grep doesn't seem to do anything with the patterns that it matches, you are correct. But in Chapter 7, "Editing Text Files," you will see how the sed command does replacements.
<BR></P>
<P>Now let's look for two or more ls (two ls followed by zero or more ls):
<BR></P>
<PRE>$ grep 'lll*' pax cron
pax:micro UNIX systems. This wi<I>ll</I> allow for easy
pax:The source wi<I>ll</I> eventually be posted to one of
cron:crontab file to your heart's content, but it wi<I>ll</I>
cron:not be re-read, and your changes wi<I>ll</I> not take
cron:level (thus ki<I>ll</I>ing cron), and then re-enter
cron:The proper way to insta<I>ll</I> a new version of a</PRE>
<P>The following command finds lines that begin with The:
<BR></P>
<PRE>$ grep '^The' pax cron
pax:The source will eventually be posted to one of
cron:The proper way to install a new version of a</PRE>
<P>The next command finds lines that end with n:
<BR></P>
<PRE>$ grep 'n$' pax cron
pax:PAX version 2. See the README file and the man
pax:for raw UNIX type read/writes can be specified on
cron:effect, until you come out of multi-user run</PRE>
<P>You can easily use the grep command to search for two or more consecutive uppercase letters:
<BR></P>
<PRE>$ grep '[A-Z]\{2,\}' pax cron
pax:This is an announcement for the <I>MS</I>-DOS version of
pax:<I>PAX</I> version 2. See the README file and the man
pax:pages for more information on how to run <I>PAX</I>,
pax:<I>TAR</I>, and CPIO.
pax:and cpio. It supports both the <I>DOS</I> filesystem
pax:micro <I>UNIX</I> systems. This will allow for easy
pax:transfer of files to and from <I>UNIX</I> systems. It
pax:for raw <I>UNIX</I> type read/writes can be specified on
cron:In <I>SCO</I> Xenix 2.3, or SCO UNIX, you can edit a</PRE>
<H5 ALIGN="CENTER">
<CENTER><A ID="I13" NAME="I13">
<FONT SIZE=3><B>The </B><B>egrep</B><B> Command</B>
<BR></FONT></A></CENTER></H5>
<P>As mentioned earlier, egrep uses full regular expressions in the pattern string. The syntax of egrep is the same as that for grep:
<BR></P>
<PRE>$egrep [options] RE [files]</PRE>
<P>where <I>RE</I> is a regular expression.
<BR></P>
<P>The egrep command uses the same regular expressions as the grep command, except for \( and \), and includes the following additional patterns:
<BR></P>
<TABLE BORDER>
<TR>
<TD>
<P>RE+</P>
<TD>
<P>Matches one or more occurrence(s) of RE. (Contrast this with grep's RE* pattern, which matches zero or more occurrences of RE.)</P>
<TR>
<TD>
<P>RE?</P>
<TD>
<P>Matches zero or one occurrence of RE.</P>
<TR>
<TD>
<P><I>RE</I>1 | <I>RE</I>2</P>
<TD>
<P>Matches either <I>RE</I>1 or <I>RE</I>2. The | acts as a logical OR operator.</P>
<TR>
<TD>
<P>(<I>RE</I>)</P>
<TD>
<P>Groups multiple regular expressions.</P></TABLE>
<P>The egrep command accepts the same command-line options as grep (see Table 6.6) as well as the following additional command-line options:
<BR></P>
<TABLE BORDER>
<TR>
<TD>
<P>-e special_expression</P>
<TD>
<P>Search for a special expression (that is, a regular expression that begins with a -)</P>
<TR>
<TD>
<P>-f file</P>
<TD>
<P>Put the regular expressions into file</P></TABLE>
<P>Here are a few examples of egrep's extended regular expressions. The first finds two or more consecutive uppercase letters:
<BR></P>
<PRE>$ egrep '[A-Z][A-Z]+' pax cron
pax:This is an announcement for the MS-DOS version of
pax:PAX version 2. See the README file and the man
pax:pages for more information on how to run PAX,
pax:TAR, and CPIO.
pax:For those of you who don't know, PAX is a 3-in-1
pax:and cpio. It supports both the DOS filesystem
pax:micro UNIX systems. This allows for easy
pax:transfer of files to and from UNIX systems. It
pax:for raw UNIX type read/writes can be specified on</PRE>
<P>The following command finds each line that contains either DOS or SCO:
<BR></P>
<PRE>$ egrep 'DOS|SCO' pax cron
pax:This is an announcement for the MS-DOS version of
pax:and cpio. It supports both the DOS filesystem
cron:In SCO Xenix 2.3, or SCO UNIX, you can edit a</PRE>
<P>The next example finds all lines that contain either new or now:
<BR></P>
<PRE>$ egrep 'n(e|o)w' cron
multi-user run level, when a new cron is started;
The proper way to install a new version of a
issue the command "crontab new.jobs", or "cat
new.jobs | crontab", or if in 'vi' with a new</PRE>
<H5 ALIGN="CENTER">
<CENTER><A ID="I14" NAME="I14">
<FONT SIZE=3><B>The </B><B>fgrep</B><B> Command</B>
<BR></FONT></A></CENTER></H5>
<P>The fgrep command searches a file for a character string and prints all lines that contain the string. Unlike grep and egrep, fgrep interprets each character in the search string as a literal character, because fgrep has no metacharacters.
<BR></P>
<P>The syntax of fgrep is
<BR></P>
<PRE>fgrep [options] string [files]</PRE>
<P>The options you use with the fgrep command are exactly the same as those that you use for egrep, with the addition of -x, which prints only the lines that are matched in their entirety.
<BR></P>
<P>As an example of fgrep's -x option, consider the following file named sample:
<BR></P>
<PRE>$ cat sample
this is
a
file for testing
egrep's x
option.</PRE>
<P>Now, invoke fgrep with the -x option and a as the pattern.
<BR></P>
<PRE>$ fgrep -x a sample
a</PRE>
<P>That matches the second line of the file, but
<BR></P>
<PRE>$ fgrep -x option sample</PRE>
<P>outputs nothing, as option doesn't match a line in the file. However,
<BR></P>
<PRE>$ fgrep -x option. sample
option.</PRE>
<P>matches the entire last line.
<BR></P>
<P><B>Files</B>
<BR></P>
<P>UNIX provides two commands that are useful when you are sorting text files: sort and uniq. The sort command merges text files together, and the uniq command compares adjacent lines of a file and eliminates all but one occurrence of adjacent duplicate
lines.
<BR></P>
<P><B>Command</B>
<BR></P>
<P>The sort command is useful with database files—files that are line- and field-oriented—because it can sort or merge one or more text files into a sequence that you select.
<BR></P>
<P>The command normally treats a blank or a tab as a delimiter. If the file has multiple blanks, multiple tabs, or both between two fields, only the first is considered a delimiter; all the others belong to the next field. The -b option tells sort to
ignore the blanks and tabs that are not delimiters, discarding them instead of adding them to the beginning of the next field.
<BR></P>
<P>The normal ordering for sort follows the ASCII code sequence.
<BR></P>
<P>The syntax for sort is
<BR></P>
<PRE>$sort [-cmu] [-ooutfile] [-ymemsize] [-zrecsize] [-dfiMnr] [-btchar]
<B>[+</B>pos1<B> [-</B>pos2<B>]] [</B>file(s)<B>]</B></PRE>
<P>Table 6.6 describes the options of sort.
<BR></P>
<UL>
<LH><B>Table 6.6. The </B><B>sort</B><B> Command's Options</B>
<BR></LH></UL>
<TABLE BORDER>
<TR>
<TD>
<PRE><I>Option</I>
<BR></PRE>
<TD>
<PRE><I>Meaning</I>
<BR></PRE>
<TR>
<TD>
<P>-c</P>
<TD>
<P>Tells sort to check only whether the file is in the order specified.</P>
<TR>
<TD>
<P>-u</P>
<TD>
<P>Tells sort to ignore any repeated lines (but see the next section, "The uniq Command").</P>
<TR>
<TD>
<P>-m</P>
<TD>
<P>Tells sort to merge (and sort) the files that are already sorted. (This section features an example.)</P>
<TR>
<TD>
<P>-zrecsize</P>
<TD>
<P>Specifies the length of the longest line to be merged and prevents sort from terminating abnormally when it sees a line that is longer than usual. You use this option only when merging files.</P>
<TR>
<TD>
<P>-ooutfile</P>
<TD>
<P>Specifies the name of the output file. This option is an
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -