Skip to main content
added 13 characters in body
Source Link
Edgar Magallon
  • 5.2k
  • 3
  • 15
  • 29

The main problem is what you said: I think it has something to do with the /.
When you use with / as delimiter you have to be careful with the strings you use.

So you should use another delimiter in your sed command:

sed -i -e "s@\${BASE64}@${myvar}@g" text.txt 

Using awk

myvar="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
awk -i inplace -v var='\\$\\{BASE64\\}' -v base="$myvar" '{sub(var,base);}1'

Another way to replace variables is by using envsubst. If in your file contains ${BASE64} you can create a variable with the same name and replace it inside the file. But you will have to export that variable (just once) before you run envsubst:

BASE64="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
export BASE64
#Not recommended: 
envsubst < text.txt | tee text.txt
#Or
envsubst < text.txt >  newtext.txt
mv newtext.txt text.txt

The main problem is what you said: I think it has something to do with the /.
When you use with / as delimiter you have to be careful with the strings you use.

So you should use another delimiter in your sed command:

sed -i -e "s@\${BASE64}@${myvar}@g" text.txt 

Using awk

myvar="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
awk -i inplace -v var='\\$\\{BASE64\\}' -v base="$myvar" '{sub(var,base);}1'

Another way to replace variables is by using envsubst. If in your file contains ${BASE64} you can create a variable with the same name and replace it. But you will have to export that variable (just once) before you run envsubst:

BASE64="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
export BASE64
#Not recommended: 
envsubst < text.txt | tee text.txt
#Or
envsubst < text.txt >  newtext.txt
mv newtext.txt text.txt

The main problem is what you said: I think it has something to do with the /.
When you use with / as delimiter you have to be careful with the strings you use.

So you should use another delimiter in your sed command:

sed -i -e "s@\${BASE64}@${myvar}@g" text.txt 

Using awk

myvar="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
awk -i inplace -v var='\\$\\{BASE64\\}' -v base="$myvar" '{sub(var,base);}1'

Another way to replace variables is by using envsubst. If your file contains ${BASE64} you can create a variable with the same name and replace it inside the file. But you will have to export that variable (just once) before you run envsubst:

BASE64="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
export BASE64
#Not recommended: 
envsubst < text.txt | tee text.txt
#Or
envsubst < text.txt >  newtext.txt
mv newtext.txt text.txt
added 86 characters in body
Source Link
Edgar Magallon
  • 5.2k
  • 3
  • 15
  • 29

The main problem is what you said: I think it has something to do with the /.
When you use with / as delimiter you have to be careful with the strings you use.

So you should use another delimiter in your sed command:

sed -i -e "s@\${BASE64}@${myvar}@g" text.txt 

Using awk

myvar="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
awk -i inplace -v var='\\$\\{BASE64\\}' -v base="$myvar" '{sub(var,base);}1'

Another way to replace variables is by using envsubst. If in your file contains ${BASE64} you can create a variable with the same name and replace it. But you will have to export that variable (just once) before you run envsubst:

BASE64="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
export BASE64
#Not recommended: 
envsubst < text.txt | tee text.txt
#Or
envsubst < text.txt >  newtext.txt
mv newtext.txt text.txt

The main problem is what you said: I think it has something to do with the /.
When you use with / as delimiter you have to be careful with the strings you use.

So you should use another delimiter in your sed command:

sed -i -e "s@\${BASE64}@${myvar}@g" text.txt 

Another way to replace variables is by using envsubst. If in your file contains ${BASE64} you can create a variable with the same name and replace it. But you will have to export that variable (just once) before you run envsubst:

BASE64="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
export BASE64
#Not recommended: 
envsubst < text.txt | tee text.txt
#Or
envsubst < text.txt >  newtext.txt
mv newtext.txt text.txt

The main problem is what you said: I think it has something to do with the /.
When you use with / as delimiter you have to be careful with the strings you use.

So you should use another delimiter in your sed command:

sed -i -e "s@\${BASE64}@${myvar}@g" text.txt 

Using awk

myvar="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
awk -i inplace -v var='\\$\\{BASE64\\}' -v base="$myvar" '{sub(var,base);}1'

Another way to replace variables is by using envsubst. If in your file contains ${BASE64} you can create a variable with the same name and replace it. But you will have to export that variable (just once) before you run envsubst:

BASE64="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
export BASE64
#Not recommended: 
envsubst < text.txt | tee text.txt
#Or
envsubst < text.txt >  newtext.txt
mv newtext.txt text.txt
added 86 characters in body
Source Link
Edgar Magallon
  • 5.2k
  • 3
  • 15
  • 29

The main problem is what you said: I think it has something to do with the /.
When you use with / as delimiter you have to be careful with the strings you use.

So you should use another delimiter in your sed command:

sed -i -e "s@\${BASE64}@${myvar}@g" text.txt 

Another way to replace variables is by using envsubst. If in your file contains ${BASE64} you can create a variable with the same name and replace it. But you will have to export that variable (just once) before you run envsubst:

BASE64="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
export BASE64
#Not recommended: 
envsubst < text.txt | tee text.txt
#Or
envsubst < text.txt >  newtext.txt
mv newtext.txt text.txt

The main problem is what you said: I think it has something to do with the /.
When you use with / as delimiter you have to be careful with the strings you use.

So you should use another delimiter in your sed command:

sed -i -e "s@\${BASE64}@${myvar}@g" text.txt 

Another way to replace variables is by using envsubst. If in your file contains ${BASE64} you can create a variable with the same name and replace it. But you will have to export that variable (just once) before you run envsubst:

BASE64="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
export BASE64
envsubst < text.txt | tee text.txt

The main problem is what you said: I think it has something to do with the /.
When you use with / as delimiter you have to be careful with the strings you use.

So you should use another delimiter in your sed command:

sed -i -e "s@\${BASE64}@${myvar}@g" text.txt 

Another way to replace variables is by using envsubst. If in your file contains ${BASE64} you can create a variable with the same name and replace it. But you will have to export that variable (just once) before you run envsubst:

BASE64="SGVsbG8gV29ybGQuIERvIHlvdSBsaWtlIG15IGJhc2U2NCBzdHJpbmc/IFRoYXQgaXMgdmVyeSBuaWNlIQ=="
export BASE64
#Not recommended: 
envsubst < text.txt | tee text.txt
#Or
envsubst < text.txt >  newtext.txt
mv newtext.txt text.txt
added 406 characters in body
Source Link
Edgar Magallon
  • 5.2k
  • 3
  • 15
  • 29
Loading
Source Link
Edgar Magallon
  • 5.2k
  • 3
  • 15
  • 29
Loading