?? ae4
字號(hào):
.NHGLOBAL COMMANDS.PPThe global commands.UL gand.UL vare used to perform one or more editing commands on all lines that eithercontain.UL g ) (or don't contain.UL v ) (a specified pattern..PPAs the simplest example, the command.P1g/UNIX/p.P2prints all lines that contain the word `UNIX'.The pattern that goes between the slashes can be anythingthat could be used in a line search or in a substitute command;exactly the same rules and limitations apply..PPAs another example, then,.P1g/^\*e\*./p.P2prints all the formatting commands in a file (lines that begin with `\*.')..PPThe.UL vcommand is identical to.UL g ,except that it operates on those line that do.ulnotcontain an occurrence of the pattern.(Don't look too hard for mnemonic significance tothe letter `v'.)So.P1v/^\*e\*./p.P2prints all the lines that don't begin with `\*.' _the actual text lines..PPThe command that follows.UL gor.UL vcan be anything:.P1g/^\*e\*./d.P2deletes all lines that begin with `\*.',and.P1g/^$/d.P2deletes all empty lines..PPProbably the most useful command that can follow a global is thesubstitute command, for this can be used to make a changeand print each affected line for verification.For example, we could change the word `Unix' to `UNIX'everywhere, and verify that it really worked, with.P1g/Unix/s//UNIX/gp.P2Notice that we used `//' in the substitute command to mean`the previous pattern', in this case, `Unix'.The .UL pcommand is done on every linethat matches the pattern,not just those on which a substitution took place..PPThe global command operates by makingtwo passes over the file.On the first pass, all lines that match the pattern are marked.On the second pass, each marked line in turn is examined,dot is set to that line, and the command executed.This means that it is possible for the command that follows a.UL gor.UL vto use addresses, set dot, and so on, quite freely..P1g/^\*e\*.PP/+.P2prints the line that follows each `.PP' command (the signal fora new paragraph in some formatting packages).Remember that `+' means `one line past dot'.And.P1g/topic/?^\*e\*.SH?1.P2searches for each line that contains `topic', scans backwards until it findsa line that begins `.SH' (a section heading) and prints the linethat follows that,thus showing the section headings under which `topic' is mentioned.Finally,.P1g/^\*e\*.EQ/+,/^\*e\*.EN/-p.P2prints all the lines that lie betweenlines beginning with `.EQ' and `.EN' formatting commands..PPThe.UL gand.UL vcommands can also bepreceded by line numbers, in which case the lines searchedare only those in the range specified..SHMulti-line Global Commands.PPIt is possible to do more than one command under the control of aglobal command, although the syntax for expressing the operationis not especially natural or pleasant.As an example,suppose the task is to change `x' to `y' and `a' to `b' on all linesthat contain `thing'.Then.P1g/thing/s/x/y/\*es/a/b/.P2is sufficient.The `\*e' signals the.UL gcommand that the set of commands continues on the next line;it terminates on the first line that does not end with `\*e'.(As a minor blemish, you can't use a substitute commandto insert a newline within a .UL gcommand.).PPYou should watch out for this problem:the command.P1g/x/s//y/\*es/a/b/.P2does.ulnotwork as you expect.The remembered pattern is the last pattern that was actuallyexecuted,so sometimes it will be`x' (as expected), and sometimes it will be `a'(not expected).You must spell it out, like this:.P1g/x/s/x/y/\*es/a/b/.P2.PPIt is also possible to execute .UL a ,.UL cand.UL icommands under a global command; as with other multi-line constructions,all that is needed is to add a `\*e' at the end of each line except the last.Thus to add a `.nf' and `.sp' command before each `.EQ' line, type.P1g/^\*e\*.EQ/i\*e\&\*.nf\*e\&\*.sp.P2There is no need for a final line containing a`\*.' to terminate the .UL icommand,unless there are further commandsbeing done under the global.On the other hand, it does no harm to put it in either.
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -