Search code examples
linuxreplacecharacterlinespecial-characters

replace a line in linux file containing special characters


Here is an extract from a script showing the variables for the script

PathToPiconPNG="/var/OscamSrvidPicon/picon/19.2E/"
PathToOscamSrvid="/var/OscamSrvidPicon/picon/19.2E/oscam.srvid"
PathToPiconTPL="/var/OscamSrvidPicon/oscam_picons/"
PathToTmp="/tmp/"

I want to run this script numerous times replacing (for example) this line:

PathToPiconPNG="/var/OscamSrvidPicon/picon/19.2E/"

with this lines

PathToPiconPNG="/var/OscamSrvidPicon/picon/28.2E/"

I have tried using sed (I know this example is wrong but you might get what im trying to achieve)

sed 's/{PathToPiconPNG="/var/OscamSrvidPicon/picon/19.2E/"}/{PathToPiconPNG="/var/OscamSrvidPicon/picon/28.2E/"}/g' filename.txt > newfilenam.txt

If that is not possible, is there any way that I can set the variable externally from another script


Solution

  • sed -E 's/picon\/.+\//picon\/28.2E\//' filename.txt > newfilenam.txt