Deleting a word in variable not knowing if it will be capitalized or not
by pedropt from LinuxQuestions.org on (#5R2WE)
in this text :
Quote:
i can use :
Code:var1="I Think John went to the house"
var2=$(echo "$var1" | sed 's/\<JOHN\>//g' | sed 's/\<John\>//g')
echo "$var2"On this next code will fail because the Capitalized john is not in variable .
Code:var1="I Think John is fine"
var2=$(echo "$var1" | sed 's/\<JOHN\>//g' | sed 's/\<John\>//g')
echo "$var2"However if in next text the 2nd john does not show up then how can i write the code for the 2 options no matter if one of them does no show up in variable?
Quote:
I Think John went to the JOHN house |
Code:var1="I Think John went to the house"
var2=$(echo "$var1" | sed 's/\<JOHN\>//g' | sed 's/\<John\>//g')
echo "$var2"On this next code will fail because the Capitalized john is not in variable .
Code:var1="I Think John is fine"
var2=$(echo "$var1" | sed 's/\<JOHN\>//g' | sed 's/\<John\>//g')
echo "$var2"However if in next text the 2nd john does not show up then how can i write the code for the 2 options no matter if one of them does no show up in variable?