原内容: EPISODE #413 – Apr 10, 2013 – 14 comments ...
输入sed 's/Apr/April/' test
会在屏幕输出: EPISODE #413 – April 10, 2013 – 14 comments ...
其中sed 's/Apr/April/' test
的's/Apr/April/'
并不一定要用单引号括住,但好的习惯是括住它,理由同 ruby 的p
例如如果这样写sed 's/ Apr/ April/' test
就必须括住了,因为空格是特殊字符
可以用分号隔开,例如sed 's/Apr /April /; s/Mar /March /' test
EPISODE #413 – April 10, 2013 – 14 comments
...
EPISODE #411 – March 27, 2013 – 20 comments
...
用-e 参数也行sed -e 's/Apr /April, /' -e 's/Mar /March, /' test
还可以分行输入
sed '
s/ Mar / March, / s/ Apr / April, /' test
(目前为止的改动不会影响 test 文件)
假如命令较多,应将命令存为脚本文件,就像这个cat sedscr
s/Apr /April, /
s/Mar /March, /
s/Feb /February, /
然后用-f 参数调用sed -f sedscr test
EPISODE #413 – April, 10, 2013 – 14 comments
...
EPISODE #411 – March, 27, 2013 – 20 comments
...
EPISODE #165 – February, 25, 2013 – 32 comments
...
(以上的改动同样不会影响 test 文件)
如果想保存所作的改动,可以保存至另一个文件sed -f sedscr test > newlist
(顺带一提,sed -f sedscr test > test
企图保存至原文件的话,test 会被清空。。。)
sed -n -e 's/Apr/April/p' test
EPISODE #413 – April 10, 2013 – 14 comments
EPISODE #412 – April 04, 2013 – 30 comments