0

我有一个名为 test 的文件,它包含:

EMS_INSTANCES_DIR=/WEB_DATA/home/edofc24/EMS-INSTANCES/async
EMS_SHARED_CONFIG=/WEB_DATA/home/edofc24/EMS-INSTANCES/async/shared/config
EMS_SHARED_DATA=/WEB_DATA/home/edofc24/EMS-INSTANCES/async/shared/data
EMS_JMS_PORT=15244
EMS_INTERFACE=tcp://adecpcas:15244
EMS_KEYS=/WEB_DATA/home/edofc24/EMS-INSTANCES/keys

我想将 = 之后的路径更改为 /test/path

我曾经sed这样做:

sed 's/\(^EMS_[SIJ].*\=\)\(\/.*[a-z]$\)/\1\/test/path/' test

但没有发生任何变化,为什么?

4

1 回答 1

1
sed 's:=/.*:=/test/path:' file

例子:

kent$  echo "EMS_INSTANCES_DIR=/WEB_DATA/home/edofc24/EMS-INSTANCES/async
EMS_SHARED_CONFIG=/WEB_DATA/home/edofc24/EMS-INSTANCES/async/shared/config
EMS_SHARED_DATA=/WEB_DATA/home/edofc24/EMS-INSTANCES/async/shared/data
EMS_JMS_PORT=15244
EMS_INTERFACE=tcp://adecpcas:15244"|sed 's:=/.*:=/test/path:'
EMS_INSTANCES_DIR=/test/path
EMS_SHARED_CONFIG=/test/path
EMS_SHARED_DATA=/test/path
EMS_JMS_PORT=15244
EMS_INTERFACE=tcp://adecpcas:15244

如果要原地更改,请添加-i

编辑评论:

sed 's@\(^EMS_[SIJ].*=/\).*@\1test/path/@' file

同样的例子:

kent$  echo "EMS_INSTANCES_DIR=/WEB_DATA/home/edofc24/EMS-INSTANCES/async
EMS_SHARED_CONFIG=/WEB_DATA/home/edofc24/EMS-INSTANCES/async/shared/config
EMS_SHARED_DATA=/WEB_DATA/home/edofc24/EMS-INSTANCES/async/shared/data
EMS_JMS_PORT=15244
EMS_INTERFACE=tcp://adecpcas:15244"|sed 's@\(^EMS_[SIJ].*=/\).*@\1test/path/@'
EMS_INSTANCES_DIR=/test/path/
EMS_SHARED_CONFIG=/test/path/
EMS_SHARED_DATA=/test/path/
EMS_JMS_PORT=15244
EMS_INTERFACE=tcp://adecpcas:15244
于 2013-08-14T21:42:11.050 回答