Sending Sed/Echo output to Variable

I have a variable $WORDS that contains a string

Then i want to use sed to break it up.

echo $WORDS | sed 's/[!-/:-@[-`{-~]/ /g'

I tried setting this as a variable by doing

WORDS2=`echo $WORDS | sed 's/[!-/:-@[-`{-~]/ /g'`

But when i do this it does not return me to the prompt properly
ie.

jmpprd-v1>
jmpprd-v1> set WORDS2=`echo $WORDS | sed 's/[!-/:-@[-`{-~]/ /g'`
>
>

Then i have to ctrl+c to exit and it does not set it.
What am i missing here?

Hi
Adding a backslash

WORDS2=`echo $WORDS | sed 's/[!-/:-@[-\`{-~]/ /g'`

Guru.

1 Like

In the line:

set WORD2=`echo $WORDS | sed 's/[!-/:-@[-`{-~]/ /g'`

you have an odd number of back-ticks (highlighted in red). Hence, the shell is waiting for another back-tick to complete the command line and displaying the secondary prompt.

Use what guruprasadpr suggested or use:

typeset WORDS2=$(echo $WORDS | sed 's/[!-/:-@[-`{-~]/ /g')

Also, I think that set should be typeset . Or are you using C shell?

Alternatively you may use tr too:

echo $WORDS | tr -d '!-/:-@[-\`{-~'

thanks for all of the suggestions/help