sed:如何替换包含某个字符串的所有行?

假设我有一个包含这些行的文件:
tomatoes
bananas
tomatoes with apples
pears
pears with apples
如何用“oranges”替换包含单词“apples”的每一行?这就是我想要的结果:
tomatoes
bananas
oranges
pears
oranges
    
已邀请:
使用
sed 's/.*apples.*/oranges/'
?     
你可以使用awk
$ awk '/apples/{$0="orange"}1' file
tomatoes
bananas
orange
pears
orange
这说要搜索苹果,然后将整个记录更改为“橙色”。     

要回复问题请先登录注册