An awk solution and a shell solution:
echo '"Hello: World"' | awk '{ gsub("[^\"]", "*", $2); print }'
We have to escape the " in [^\"] since the regular expression itself is in double quotes. This generates
"Hello: *****"
With the shell (at least bash and ksh93):
echo '"Hello: World"' | {
read -r prefix rest
printf '%s %s\n' "$prefix" "${rest//[^\"]/*}"
}
Assuming the text "Hello: World" is on a line of its own, but embedded in a larger text in the file greetings.txt:
awk '/"Hello: [^"]*"/ { gsub("[^\"]", "*", $2) } { print }' greetings.txt >greet.tmp && mv greet.tmp greeting.txt
or (again, with bash or ksh93),
while read -r prefix rest; do
if [[ "$prefix" =~ ^\"Hello: ]]; then
rest=${rest//[^\"]/*}
fi
printf '%s %s\n' "$prefix" "$rest"
done <greetings.txt >greet.tmp
mv greet.tmp greetings.txt
For the input
Specific recipients:
"Hello: Mom!"
"Hello: Cat!"
General recipients:
"Hello: World!"
these two solutions generate
Specific recipients:
"Hello: ****"
"Hello: ****"
General recipients:
"Hello: ******"