1

Having following bash script to update key value of my config file

#!/bin/bash

ipaddr="192.168.0.1"
path="my/binary/file/path/version_op.bin"

sed -i "s/\("IP_ADDR" *= *\).*/\1$ipaddr/" config.txt

sed -i "s/\("PATH_N_FILENAME" *= *\).*/\1${path}/" config.txt

config file (config.txt) content

IP_ADDR=192.168.0.1

PATH_N_FILENAME=NO_PATH

Above scripts working fine for only update IP_ADDR but when i enable sed for PATH_N_FILENAME then it show me following error.

sed: -e expression #1, char 35: unknown option to `s'

might be this issue occurs because of path variable contain / in path and it put sed in confusion state.but what ever issue , still i could not find it.

Have any one idea how to resolve it?

Jayesh Bhoi
  • 24,694
  • 15
  • 58
  • 73
  • 1
    Use a different separator. This is a __FAQ__. – devnull Mar 04 '14 at 09:20
  • possible duplicate of [sed command : How to use variable](http://stackoverflow.com/questions/19151954/sed-command-how-to-use-variable) – devnull Mar 04 '14 at 09:21
  • @devnull you are right using different separator it will fix.t try as follows `sed -i "s|\("PATH_N_FILENAME" *= *\).*|\1${path}|" input.txt` and it works fine...Thanks – Jayesh Bhoi Mar 04 '14 at 09:30
  • possible duplicate of [Escape a string for a sed replace pattern](http://stackoverflow.com/questions/407523/escape-a-string-for-a-sed-replace-pattern) – oberlies Apr 04 '14 at 11:34

1 Answers1

0

use single-quote in sed command section :

sed -i 's/\("IP_ADDR" *= *\).*/\1$ipaddr/' config.txt
Farvardin
  • 5,336
  • 5
  • 33
  • 54