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.
(编辑:我爱制作网_沈阳站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
- Linux etcrc.drc.local配置文件用法介绍
- linux – 我的进程如何检测计算机是否正在关闭?
- c – GDB在启动时崩溃(内部错误:follow_die_offset)
- 过年送这个倍儿有面儿!四季沐歌太阳能热水器3680元
- linux-kernel – 绑定驱动程序如何从奴役接口获取RX数据包
- Linux tail命令显示文件结尾的内容
- 10 Linux DIG Command Examples for DNS Lookup--reference
- 唱吧怎么上榜 长沙style恶霸堂客上榜分析
- Jvm原理分析,看了都说好
- linux – 使用10GB内存的Haproxy和50k连接的100%CPU

