Sed error : bad option in substitution expression

后端 未结 2 1627
南笙
南笙 2020-12-06 18:02

I have a configuration file (gpsd.default) containing data with the following format:

# If you must specify a non-NMEA driver, uncomment and mod         


        
相关标签:
2条回答
  • 2020-12-06 18:38

    This is because you are using a regex containing /, which is the same character sed uses as delimiter.

    Just change the sed delimiter to another one, for example ~:

    sed -i 's~^GPS_DEVICES="".*~GPS_DEVICES="dev/ttyUSB1"~' /etc/default/gpsd.default
    

    By the way, since you are changing files in /etc, you may want to use -i.bak, so that the original file gets backed up. It is a good practice to prevent loss of important information.

    0 讨论(0)
  • 2020-12-06 18:45

    You should update your sed command to this.

    sed -i 's/^GPS_DEVICES=\"\".*/GPS_DEVICES=\"dev\/ttyUSB1\"/' /etc/default/gpsd.default
    
    0 讨论(0)
提交回复
热议问题