LMLPHP后院

Linux Bash Sed 的使用

原文链接 : http://blog.lmlphp.com/tutorial/1/SHELL/item/23/Use_of_Linux_Bash_Sed  来自 : LMLPHP后院

文本文件内容 a.txt。

this is a dog
this is a dog
this is a dog
this is a cat
this is a cat
this is a cat
this is a dog

sed 按照行替换,将第 2,3 行的 dog 替换为 cat:

$ sed '2,3s/dog/cat/' a.txt
this is a dog
this is a cat
this is a cat
this is a cat
this is a cat
this is a cat
this is a dog

按照正则条件进行替换,将含有 dog 一行的 this 替换为 that:

$ sed '/dog/s/this/that/' a.txt
that is a dog
that is a dog
that is a dog
this is a cat
this is a cat
this is a cat
that is a dog
LMLPHP,可爱滴WEB开发框架

2017-09-24 00:34:12 1506184452 0.003257