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

📄 e3

📁 UNIX v6源代码 这几乎是最经典的unix版本 unix操作系统设计和莱昂氏unix源代码分析都是用的该版
💻
字号:
.H1The current line \(mi ``Dot'' or ``.''.H2.PGSuppose our buffer still contains the six lines as above,that we have just typed.X11,3p.X2and.uledhas printed the three lines for us.Try typing just.X1p	(no line numbers)..X2This will print.X1to come to the aid of their party..X2which is the third line of the buffer.In fact it is the last(most recent) line that we have done anything with.(We just printed it!)We canrepeat this ``p'' command without line numbers, andit will continue to print line 3..PGThe reason is that.uledmaintains a record of the last linethat we did anything to (in this case, line 3, which wejust printed) so that it can be used instead of an explicitline number.This most recent line is referred to by theshorthand symbol.X1.li\fB.\fR	(pronounced ``dot'')..X2Dot is a line number in the same way that ``$'' is; it meansexactly ``the current line'', or loosely,``the line we most recently did something to.''Wecan use it in several ways \(mi one possibilityis to say.X1.li\fB.\fR,$p.X2This will print all the lines from (including) the currentline to theend of the buffer.In our case these are lines 3 through 6..PGSome commands change the value of dot, while others do not.The print command sets dot to the number of the last line printed;by our last command, we would have ``\*.'' = ``$'' = 6..PGDot is most useful when used in combinations like this one:.X1.li\fB.\fR+1	(or equivalently, \*.+1p).X2This means ``print the next line'' and gives us a handy way to stepslowly through a buffer.We can also say.X1.li\fB.\fR\(mi1	(or \*.\(mi1p ).X2which means ``print the line.ulbeforethe current line.''This enables us to go backwards if we wish.Another useful one is something like.X1.li\fB.\fR\(mi3,\*.\(mi1p.X2which prints the previous three lines..PGDon't forget that all of these change the value of dot.You can find out what dot is at any time by typing.X1.li\fB.\fR=.X2.ulEdwill respond by printing the value of dot..PGLet's summarize some things about the ``p'' commandand dot.Essentially ``p'' can be preceded by 0, 1, or 2 line numbers.If there is no line number given, it prints the ``current line'',the line that dot refers to.If there is one line number given(with or without the letter ``p''),it prints that line (and dot is set there); and if thereare two line numbers, it prints all the lines in that range(and sets dot to the last line printed.)If two line numbers are specifiedthe first can't be bigger than the second (see Exercise 2.).PGTyping a single newline will cause printing of the next line \(miit'sequivalent to ``\*.+1p''.Try it.Try typing ``^'' \(mi it's equivalent to``\*.\(mi1p''..H1Deleting lines: the ``d'' command.H2.PGSuppose we want to get rid of the three extra lines in the buffer.This is done by the.uldeletecommand.X1d.X2Except that ``d'' deletes lines instead of printing them,its action is similar to that of ``p''.The lines to be deleted are specified for ``d''exactly as they are for ``p'':.X1\fIstarting line, ending line\fP d.X2Thus the command.X14,$d.X2deletes lines 4 through the end.There are now three lines left, as we can check by using.X11,$p.X2And notice that ``$'' now is line 3!Dotis set to the next line after the last line deleted,unless the last line deleted is the last line in the buffer.In that case, dot is set to ``$''..H1Exercise 4:.H2.PGExperiment with ``a'', ``e'', ``r'', ``w'', ``p'', and ``d''until you are sure that youknow what they do, and until you understand how dot, ``$'', andline numbers are used..PGIf you are adventurous, try using line numbers with ``a'', ``r'', and``w'' as well.You will find that ``a'' will append lines.ulafterthe line number that you specify (rather than after dot); that ``r'' readsa file in.ulafterthe line number you specify (not necessarilyat the end of the buffer); and that ``w'' will write out exactly the linesyou specify, not necessarily the whole buffer.These variations are sometimes handy.For instance you can insert a file at the beginning of a bufferby saying.X10r filename.X2and you can enter lines at the beginning of the bufferby saying.X10a.li. . . \fItext\fP . . ..li\fB.\fR.X2Notice that``\*.w'' is.ulverydifferent from.X1.li\fB.\fRw.X2.H1Modifying text: the Substitute command ``s''.H2.PGWe are now ready to try one of the most importantof all commands \(mi the substitute command.X1s.X2This is the commandthat is used to change individualwords or letters within a line or group of lines.It is what we use, for example, for correcting spellingmistakes and typing errors..PGSuppose that by a typing error, line 1 says.X1Now is th time.X2\(mi the ``e'' has been left off ``the''.We can use ``s'' to fix this up as follows:.X11s/th/the/.X2This says: ``in line 1, substitute for the characters `th'the characters `the'.''To verifythat it works (\fIed\fR will not printthe result automatically) we say.X1p.X2and get.X1Now is the time.X2which is what we wanted.Notice that dot must have been set to the linewhere the substitution took place, since the ``p'' commandprinted that line.Dot is always set this way with the ``s'' command..PGThe general way to use the substitute command is.X1\fIstarting-line, ending-line\fP s/\fIchange this\fP/\fIto this\fP/.X2Whatever string of characters is between the first pair ofslashes is replaced by whatever is between the second pair,in.ulallthe lines between starting line and ending line.Only the first occurrence on each line is changed, however.If you want to change.uleveryoccurrence, see Exercise 5.The rules for line numbers are the same as those for ``p'',except that dot is set to the last line changed.(But there is a trap for the unwary: if no substitutiontook place, dot is.ulnotchanged.This causes an error ``?'' as a warning.).PGThus we can say.X11,$s/speling/spelling/.X2and correct the first spelling mistakeon each linein the text.(This is useful for people who are consistentmisspellers!).PGIf no line numbers are given, the ``s'' command assumes we mean``make the substitution on line dot'', so it changes things onlyon the current line.This leads to the very common sequence.X1s/something/something else/p.X2which makes some correction on thecurrent line, and then prints it, to make sure itworked out right.If it didn't,we can try again.(Notice that we puta print command on the same line as the substitute.With few exceptions, ``p'' can follow any command;no other multi-command lines are legal.).PGIt's also legal to say.X1s/ . . . //.X2which means ``change the firststring of characters to\fInothing\fR'',i.e.,remove them.This is useful for deleting extra words in a line or removing extraletters from words.For instance, if we had.X1Nowxx is the time.X2we can say.X1s/xx//p.X2to get.X1Now is the time.X2Notice that ``//'' here means ``no characters'', not a blank.There.ulisa difference!(See below for another meaning of ``//''.)

⌨️ 快捷键说明

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