sed:
sed 默认读取整个文件并对其中的每一行进行修改。
1、原文件内容保持不变
2、输出可以被重定向到另一文件中,以保存变化
sed [options] ‘{command}’ [filename]
替换命令:
‘s/{old value}/{new value}/’
e.g.
$ echo The tiger cubs will meet on Tuesday after school | sed
‘s/tiger/wolf/’
The wolf cubs will meet on Tuesday after school
多次修改:
$ echo The tiger cubs will meet on Tuesday after school | sed ’
s/tiger/wolf/; s/after/before/’
The wolf cubs will meet on Tuesday before school
or
$ echo The tiger cubs will meet on Tuesday after school | sed -e ’
s/tiger/wolf/’ -e ‘s/after/before/’
The wolf cubs will meet on Tuesday before school
$
全局处理
$ echo The tiger cubs will meet this Tuesday at the same time
as the meeting last Tuesday | sed ‘s/Tuesday/Thursday**/g**’
The tiger cubs will meet this Thursday at the same time
as the meeting last Thursday
$
来源自网络