1

I have this text string within a configuration file:

jdbcService.oraclePool.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracleserver.example.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=oracleserver55)))

I'd like to replace with sed the value "(HOST=oracleserver.example.com)" without sticking to the text after the = symbol. I tried to use several regexp but cannot find the working one:

# sed 's/\((HOST=.*?)\)/(HOST=newvalue)/' customer_overrides.properties
jdbcService.oraclePool.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracleserver.example.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=oracleserver55)))

# sed -E 's/\((HOST=.*?)\)/(HOST=newvalue)/' customer_overrides.properties | grep HOST=
jdbcService.oraclePool.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=newvalue)

# sed 's/\((HOST=.*[^)])\)/(HOST=newvalue)/' customer_overrides.properties | grep HOST=
jdbcService.oraclePool.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=newvalue)))

I am working on:

  • linux RH7
  • sed-4.2.2-5.el7.x86_64

Thanks for your help!

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
EBAH
  • 99
  • 9

2 Answers2

1
sed 's/HOST=[^)]*/HOST=foobar/' file

Output:

jdbcService.oraclePool.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=foobar)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=oracleserver55)))
Cyrus
  • 84,225
  • 14
  • 89
  • 153
1

If you don't need to stick to sed this is a good alternative:

perl -pi -e 's/\((HOST=.*?)\)/(HOST=foobar)/g' customer_overrides.properties

But I prefer Cyrus' reply :)

EBAH
  • 99
  • 9