Say I have a file containing these lines:
tomatoes
bananas
tomatoes with apples
pears
pears with apples
Ho开发者_JAVA技巧w do I replace every line containing the word "apples" with just "oranges"? This is what I want to end up with:
tomatoes
bananas
oranges
pears
oranges
Use sed 's/.*apples.*/oranges/'
?
you can use awk
$ awk '/apples/{$0="orange"}1' file
tomatoes
bananas
orange
pears
orange
this says to search for apples, then change the whole record to "orange".
精彩评论