Reputation: 5480
I have a variable in Linux
like below. This is not a valid variable I just created to test how to replace characters with some new characters.
table=123~!@#$%^&*()+|}{:"?><-=[]\;',./
Want to replace all the special characters in this table variable like below
table1=123_____________________________
How can I do that in Linux?
Upvotes: 0
Views: 54
Reputation: 50019
Pipe it to sed
and replace anything that is not ^
alphanumeric [:alnum:]
with an underscore _
.
sed 's/[^[:alnum:]]/_/g'
In your code, this would look something like:
table1=$(echo table | sed 's/[^[:alnum:]]/_/g')
Upvotes: 1