sed [option] [commands] file
sed 四个执行过程:
读入:
将 file 第一行内容读入内存中(sed自带的内存空间)
执行:
使用内存空间中的内容来执行commands
打印:
打印内容(因为四个执行过程的顺序是依次执行,所以打印的是内容执行commands的结果;需要说明的是如果没有执行commands(比如替换命令),就打印file本身内容,最后清空内存空间内容
重复:
读入file第二行内容到内存中,执行上述过程,直至file最后一行为止
小技巧: sed -n commands file :
其中-n 作用是屏蔽打印过程,即让sed执行过程变为:读——>执行——>重复,因为没有打印过程,这时屏幕没有输出;
commands: p 打印命令
sed -n ‘commands p’ file :所以 -n 和 p 的组合为只打印执行commands的内容