sed工作在一条线上,而不是另一条线

时间:2014-11-07 01:36:08

标签: bash sed centos

这里有几行脚本,除第一行外,一切都有效。

sed -i '/    "download-dir": "/var/lib/transmission/Downloads", /c\    "download-dir": "/media/hdd_bottom_left/transmission/downloads", ' /var/lib/transmission/settings.json
sed -i '/    "download-queue-size": 5, /c\    "download-queue-size": 6, ' /var/lib/transmission/settings.json
sed -i '/    "peer-limit-global": 200, /c\    "peer-limit-global": 1200, ' /var/lib/transmission/settings.json
sed -i '/    "peer-limit-per-torrent": 50, /c\    "peer-limit-per-torrent": 180, ' /var/lib/transmission/settings.json
sed -i '/    "port-forwarding-enabled": true, /c\    "port-forwarding-enabled": false, ' /var/lib/transmission/settings.json
sed -i '/    "rpc-whitelist": "127.0.0.1", /c\    "rpc-whitelist": "127.0.0.1,10.0.1.2,10.0.1.3", ' /var/lib/transmission/settings.json
sed -i '/    "script-torrent-done-enabled": false, /c\    "script-torrent-done-enabled": true, ' /var/lib/transmission/settings.json
sed -i '/    "script-torrent-done-filename": "", /c\    "script-torrent-done-filename": "/media/hdd_bottom_left/transmission/script/post-process", ' /var/lib/transmission/settings.json
sed -i '/    "speed-limit-up": 100, /c\    "speed-limit-up": 5000, ' /var/lib/transmission/settings.json
sed -i '/    "speed-limit-up-enabled": false, /c\    "speed-limit-up-enabled": true, ' /var/lib/transmission/settings.json
sed -i '/    "upload-slots-per-torrent": 14, /c\    "upload-slots-per-torrent": 11, ' /var/lib/transmission/settings.json

这是错误:

[root@Server transmission]# sed -i '/    "download-dir": "/var/lib/transmission/Downloads", /c\    "download-dir": "/media/hdd_bottom_left/transmission/downloads", ' /var/lib/transmission/settings.json
sed: -e expression #1, char 55: expected newer version of sed
[root@Server transmission]# 

1 个答案:

答案 0 :(得分:3)

如果你想/需要在表达式中使用它们,你需要转义分隔符(/):

sed -i '/    "download-dir": "\/var\/lib\/transmission\/Downloads", /c\    "download-dir": "\/media\/hdd_bottom_left\/transmission\/downloads", ' /var/lib/transmission/settings.json