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

📄 e3

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻
字号:
.SHThe current line \- ``Dot'' or ``.''.PPSuppose your buffer still contains the six lines as above,that you have just typed.P11,3p.P2and.uledhas printed the three lines for you.Try typing just.P1p	(no line numbers).P2This will print.P1to come to the aid of their party..P2which is the third line of the buffer.In fact it is the last(most recent) line that you have done anything with.(You just printed it!)You canrepeat this.UL pcommand without line numbers, andit will continue to print line 3..PPThe reason is that.uledmaintains a record of the last linethat you did anything to (in this case, line 3, which youjust printed) so that it can be used instead of an explicitline number.This most recent line is referred to by theshorthand symbol.P1\&\*.	(pronounced ``dot'')..P2Dot is a line number in the same way that.UL $is; it meansexactly ``the current line'', or loosely,``the line you most recently did something to.''Youcan use it in several ways \- one possibilityis to say.P1\&\*.,$p.P2This will print all the lines from (including) the currentline to theend of the buffer.In our example these are lines 3 through 6..PPSome commands change the value of dot, while others do not.The.UL pcommand sets dot to the number of the last line printed;the last command willset both\*.and.UL $to 6..PPDot is most useful when used in combinations like this one:.P1\&\*.+1	(or equivalently, \*.+1p).P2This means ``print the next line'' and is a handy way to stepslowly through a buffer.You can also say.P1\&\*.\-1	(or \*.\-1p ).P2which means ``print the line.ulbeforethe current line.''This enables you to go backwards if you wish.Another useful one is something like.P1\&\*.\-3,\*.\-1p.P2which prints the previous three lines..PPDon't forget that all of these change the value of dot.You can find out what dot is at any time by typing.P1\&\*.=.P2.ulEdwill respond by printing the value of dot..PPLet's summarize some things about the.UL pcommandand dot.Essentially.UL pcan 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.UL 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.).PPTyping a single return will cause printing of the next line \-it'sequivalent to.UL .+1p .Try it.Try typinga.UL \- ;you will find thatit's equivalent to.UL .\-1p ..SHDeleting lines: the ``d'' command.PPSuppose you want to get rid of the three extra lines in the buffer.This is done by the.uldeletecommand.P1d.P2Except that.UL ddeletes lines instead of printing them,its action is similar to that of.UL p .The lines to be deleted are specified for.UL dexactly as they are for.UL p :.P1\fIstarting line, ending line\fP d.P2Thus the command.P14,$d.P2deletes lines 4 through the end.There are now three lines left, as you can check by using.P11,$p.P2And notice that.UL $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.UL $ ..SHExercise 4:.PPExperiment with.UL a ,.UL e ,.UL r ,.UL w ,.UL pand.UL duntil you are sure that youknow what they do, and until you understand how dot,.UL $ ,andline numbers are used..PPIf you are adventurous, try using line numbers with.UL a ,.UL rand.UL was well.You will find that.UL awill append lines.ulafterthe line number that you specify (rather than after dot); that.UL rreadsa file in.ulafterthe line number you specify (not necessarilyat the end of the buffer); and that.UL wwill 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.P10r filename.P2and you can enter lines at the beginning of the bufferby saying.P10a\&. . . \fItext\fP . . .\*..P2Notice that.UL .wis.ulverydifferent from.P1\*.w.P2.SHModifying text: the Substitute command ``s''.PPWe are now ready to try one of the most importantof all commands \- the substitute command.P1s.P2This is the commandthat is used to change individualwords or letters within a line or group of lines.It is what you use, for example, for correcting spellingmistakes and typing errors..PPSuppose that by a typing error, line 1 says.P1Now is th time.P2\- the.IT ehas been left off.IT the .You can use.UL sto fix this up as follows:.P11s/th/the/.P2This says: ``in line 1, substitute for the characters.IT ththe characters.IT the .''To verifythat it works.IT ed "" (will not printthe result automatically) say.P1p.P2and get.P1Now is the time.P2which is what you wanted.Notice that dot must have been set to the linewhere the substitution took place, since the.UL pcommandprinted that line.Dot is always set this way with the.UL scommand..PPThe general way to use the substitute command is.P1\fIstarting\(hyline, ending\(hyline\fP s/\fIchange this\fP/\fIto this\fP/.P2Whatever string of characters is between the first pair ofslashes is replaced by whatever is between the second pair,in.ulallthe lines between.ulstarting-lineand.ulending-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.UL 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.UL ?as a warning.).PPThus you can say.P11,$s/speling/spelling/.P2and correct the first spelling mistakeon each linein the text.(This is useful for people who are consistentmisspellers!).PPIf no line numbers are given, the.UL scommand assumes we mean``make the substitution on line dot'', so it changes things onlyon the current line.This leads to the very common sequence.P1s/something/something else/p.P2which makes some correction on thecurrent line, and then prints it, to make sure itworked out right.If it didn't,you can try again.(Notice that there isa.UL pon the same line as the.UL scommand.With few exceptions,.UL pcan follow any command;no other multi-command lines are legal.).PPIt's also legal to say.P1s/ . . . //.P2which means ``change the firststring of characters to.IT nothing '', ``i.e.,remove them.This is useful for deleting extra words in a line or removing extraletters from words.For instance, if you had.P1Nowxx is the time.P2you can say.P1s/xx//p.P2to get.P1Now is the time.P2Notice that.UL //(two adjacent slashes) means ``no characters'', not a blank.There.ulisa difference!(See below for another meaning of.UL // .)

⌨️ 快捷键说明

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