Reputation: 749
I want to be able to replace entire phrases like:
white_phone
white; phone
white.phone
phone;white
with a single phrase "REJECT" based on whether the word "white" is in the phrase. I have tried using:
sed -e 's/*white*/REJECT/g' -e 's/*white/REJECT/g' -e 's/white*/REJECT/g' file
but this only replaces the word "white" and leaves the remainder of the phrase, which I don't want.
The phrases are tab delimited too, if that helps.
Upvotes: 1
Views: 162
Reputation: 1008
This will give you the output you want, as I understand you neeed. If it is not the case, please show an example of your desired output.
sed -i 's/.*white.*/REJECT/' file
Upvotes: 2
Reputation: 16834
You need to use sed backreferences for this:
sed -e 's/\(^.*\)white.*phone\(.*$\)/\1REJECT\2/g' -e 's/\(^.*\)phone.*white\(.*$\)/\1REJECT\2/g' < file
That command works for me with the input you provided.
Upvotes: 0