Sed - An Introduction and Tutorial by Bruce Barnett
The character "^I" is a?CTRL-I?or tab character. You would have to explicitly type in the tab. Note the order of operations above,which is in that order for a very good reason. Comments might start in the middle of a line,with white space characters before them. Therefore comments are first removed from a line,potentially leaving white space characters that were before the comment. The second command removes all trailing blanks,so that lines that are now blank are converted to empty lines. The last command deletes empty lines. Together,the three commands remove all lines containing only comments,tabs or spaces. This demonstrates the pattern space?sed?uses to operate on a line. The actual operation?sed?uses is:
Another useful command is the print command: "p." If?sed?wasn't started with an "-n" option,the "p" command will duplicate the input. The command sed 'p' will duplicate every line. If you wanted to double every empty line,use: sed '/^$/ p' Adding the "-n" option turns off printing unless you request it. Another way of duplicating?head's functionality is to print only the lines you want. This example prints the first 10 lines: sed -n '1,10 p' |
sed -n '1,10 p' sed -n '11,$ !p' sed '1,10 !d' sed '11,$ d'
It also shows that the "!" command "inverts" the address range,operating on the other lines.
There is one more simple command that can restrict the changes to a set of lines. It is the "q" command: quit. the third way to duplicate the head command is:
sed '11 q'
which quits when the eleventh line is reached. This command is most useful when you wish to abort the editing after some condition is reached.
The "q" command is the one command that does not take a range of addresses. Obviously the command
sed '1,10 q'
cannot quit 10 times. Instead
sed '1 q'
or
sed '10 q'
is correct.
The curly braces,"{" and "}," are used to group the commands.
(编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!