我有一个文件调用config.txt
,其中包含类似的内容。
[MS-SQL]
DRIVER : FreeTDS
SERVER : 138.23.21.45
我需要做的是,SERVER :
之后包含的字符串值是否需要替换为$SERVER_IP
等shell变量中的内容。
最终config.ini
需要像这样。
(考虑bash shell变量包含一些像$SERVER_IP=192.168.5.3
)
[MS-SQL]
DRIVER : FreeTDS
SERVER : 192.168.5.3
答案 0 :(得分:1)
这会改变这一行:
"children": [
{
"url": "foo.pdf",
"expanded": false,
"label": "E14288-Passive-40085-2014_09_26.pdf",
"last_modified": "2014-09-28T11:19:49.000Z",
"type": 1,
"size": 60929
}
]
说明
sed -iE 's/(SERVER : )([0-9.]+)/\1'"$SERVER_IP"'/' config.txt
如果您愿意,也可以在-i # write changes to the file "in place".
-E # Use extended regex (to avoid the need
# of backslash in `()`)
's/ … / … /' # Use the substitute command.
(SERVER : ) # Match the string you need `SERVER : ` capturing it
# in the first group of parenthesis.
([0-9.]+) # capture digits and dots in the second group.
/\1'"$SERVER_IP"'/' # write the contents of the first group and
# the value of the variable to the file.
config.txt # name of the file.
之后更改值:
DRIVER