0

we have running tomcat server and in server.xml file we have password=secret I want to search and replace my password with xxxxxxx string. how do i craft regex for it? following is line where password i located in server.xml file

<Resource auth="Container" description="Database connection for Production" driverClassName="oracle.jdbc.OracleDriver" factory="org.apache.commons.dbcp.BasicDataSourceFactory" maxActive="25" maxIdle="5" maxWait="5000" name="jdbc/osdb" password="secret" type="javax.sql.DataSource" url="jdbc:oracle:thin:@DB0001" username="admin"/>
Johannes Weiss
  • 52,533
  • 16
  • 102
  • 136
Satish
  • 16,544
  • 29
  • 93
  • 149
  • 2
    [Why on earth would you want to parse XML with a regex?](http://stackoverflow.com/a/1732454/725418) – TLP Feb 16 '12 at 21:04

1 Answers1

3

Would something like:

sed -i 's/password="[a-zA-Z0-9]\+"/password="foo"/g' server.xml

do the job for you or are you expecting there to be other lines like password="xyz" ?

Pollett
  • 596
  • 4
  • 15
  • 2
    You don't even need [a-zA-Z0-9] as he already gave you the string to replace ("secret"). –  Feb 16 '12 at 21:03
  • [a-zA-Z0-9] is required because we have 2/3 different passwords in same file. ("secret") was example :) – Satish Feb 16 '12 at 21:23
  • 1
    @Pollett I suggest you use `[[:alnum:]]` over `[a-zA-Z0-9]` as not only is it shorter but it also works across all locales – SiegeX Feb 17 '12 at 08:53
  • I have encounter is new problem. I have few passwords which has special character like #!@%^& so [a-zA-Z0-9] regex doesn't working there. How do i match special character in regexp – Satish Apr 13 '12 at 13:52