Treat special characters

Asked

Viewed 242 times

0

I am treating the CURL return with SED, but as the information I receive but sometimes has the character / causes an error in the SED syntax.

TOKEN=$(curl --silent $URL | awk -F '"' '/content/ {print $2}')
echo $TOKEN

2CTVaTm46Uoregv0VcU2QPd15B3G/Opngx7iavl9cns=

sed -e "s/@TOKEN/$TOKEN/" $JSON_FILE > /tmp/$NAME.json

sed: -e Expression #1, char 39: Unknown option to `s'

How can I specify for SED that when there is / in the substitution variable it should not interpret as command?

  • 2

    Use another character, for example ; instead of the bar. Ex: sed -e "s;@TOKEN;$TOKEN;"

  • I didn’t know I could use another character as a separator, so I decided because in return there is no ; Thanks

1 answer

0

No sed, pass the "backslash" before the normal slider.

Ex: sed '/channelType/,/\/channelType/!d' file.log

In the above command I’m taking a chunk of the log that goes from "channelType" until "/channelType".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.