String Replace by *

Hi,

I want to replace the string with * using shell commands

For e.g,

MyString : test

Output : ****

Please Suggest me,
Regards,
Nanthagopal A

One way:

mystring='test'
mystring=$(echo "$mystring" | awk '{for(i=0;i<length($0);i++) {printf("*")} }' )
echo "$mystring"

can you please try

tr [a-z] * filename
sed '1,$/[a-z]/*/g filename

bash/ksh93:

echo "${MyString//?/*}"

alternative:

echo "$MyString"|sed 's/./*/g'

I guess :slight_smile: you want to hide password when input?

http://www.unix.com/shell-programming-scripting/22587-hide-password.html

stty -echo
read $passwd
stty echo

Thank you for your reply.

I have used the above command as follows,

#!/bin/bash

fnid() {
final=$(echo $1 | awk '{for(i=0;i<length($0);i++) {printf("*")} }' FS= OFS= )
echo $final
}

id="5339087"
updatedid=$(fnid $id )
echo $updatedid

I got the output,

list of file names in the path instead of ******

Please Suggest me,

Regards,
Nanthagopal A

Quoting is essential - read jims post carefully.

...
echo "$updatedid"

will show the asterisks.
Another way to solve the problem:

echo "5339087" |tr '[:print:]' '*'
1 Like

Here's one more, depending on the features of your shell, working in bash:

$ id="245235"
$ uid=${id//?/\*}
$ echo "$uid"
******