This command will return the replace the OLD value with NEW for the STRING.
NOTE: we'll use the option -nl
to append a new line to the output
and make it easier to read.
string -nl replace "friendly" "enemies" "The people were friendly"
Would return The people were enemies
string replace "tomato" "ememies" "The people were friendly"
Would return The people were friendly
NOTE: To read content from standard input we use the -i -
option.
echo "The people were friendly" | string -nl -i - replace "friendly" "enemies"
Would return The people were enemies
echo "The people were friendly" | string -nl -i - replace "apple" "enemies"
Would return The people were friendly