原文件内容如下:
#my pig is white
#his cat is pigtest is black
将其中以pig开头的单词替换为dog
sed 's/\s\+pig.*\s\+/ dog /g' sedtest,(注意+之前要加\,否则无法识别),结果如下:
#my dog white
#his cat is dog black
接下来替换包含pig的单词,文件如下,
#my pig is white
#his cat is mypigtest is black
sed 's/\s\+[a-z]*pig.*\s\+/ dog /g' sedtest,结果为
#my dog white
#his cat is dog black