I need to create a script that replaces all letters of a word after a certain word with an asterisk (*
).
For example:
sed 's/Word:[^ ]\+/Word:*/' Desktop/script_test
But this script replaces the entire word with only one asterisk, while I want to replace all letters. How can I do that?
For example, with this input:
Word: cat
I want to get
Word: ***
I am running Linux.
P.S. The input must be read from a text file and also saved to the same file.
Best Answer
You could do it one at a time in a loop:
To edit the file in place and assuming all the characters to replace are single-byte, you can make both sed's stdin and stdout the file as in:
Or with GNU sed, use the
-i
flag as in:(Though that will replace the file with a new one (though with the same name). With BSD sed, use
-i ''
instead of-i
).