0

i'm not very good at scritping so a i need a hand on this.

i have the following output that i want to parse data from:

Actual Output:

<connection-pool name="name1" max-connections="50" min-connections="5">
<connection-factory factory-class="oracle.jdbc.pool.OracleDataSource" user="user1" password="xxxx" url="jdbc:oracle:thin:@server1.domain.com:1550:name1" commit-record-table-name="">
<connection-pool name="name2" max-connections="50" min-connections="5">
<connection-factory factory-class="oracle.jdbc.pool.OracleDataSource" user="user2" password="xxxx" url="jdbc:oracle:thin:@server2.domain.com:1524:name2" commit-record-table-name="">
<connection-pool name="name3" max-connections="15" min-connections="5">
<connection-factory factory-class="oracle.jdbc.pool.OracleDataSource" user="user3" password="xxxx" url="jdbc:oracle:thin:@server3.domain.com:1528:name3" commit-record-table-name="">
<connection-pool name="name4" initial-limit="1" max-connections="10" min-connections="1" num-cached-statements="5">
<connection-factory factory-class="oracle.jdbc.pool.OracleDataSource" user="user4" password="xxxx" url="jdbc:oracle:thin:@server4.domain.com:1538:name4" commit-record-table-name=""/>
<connection-pool name="name5" initial-limit="1" max-connections="10" min-connections="1" num-cached-statements="5">
<connection-factory factory-class="oracle.jdbc.pool.OracleDataSource" user="user5" password="xxxx" url="jdbc:oracle:thin:@//server5.domain.com:1537/name5"/>

Desired Output:

name="name1" max-connections="50" min-connections="5" url="jdbc:oracle:thin:@server1.domain.com:1550:name1"
name="name2" max-connections="50" min-connections="5" url="jdbc:oracle:thin:@server2.domain.com:1524:name2"
name="name3" max-connections="15" min-connections="5" url="jdbc:oracle:thin:@server3.domain.com:1528:name3"
name="name4" max-connections="10" min-connections="1" url="jdbc:oracle:thin:@server4.domain.com:1538:name4"
name="name5" max-connections="10" min-connections="1" url="jdbc:oracle:thin:@//server5.domain.com:1537/name5"

I would appreciate if someone could help me on this, btw it should be done in bash, since i cant install software on all production servers..

thanks in advance!!

8
  • Do your production servers really not already ship with Python, or any other language with XML support in the standard library? Parsing XML with bash requires 3rd-party tools -- xmlstarlet, xmllint, etc. Commented Feb 18, 2014 at 16:20
  • Take a look at this answer: stackoverflow.com/a/13463365/1050015 Commented Feb 18, 2014 at 16:21
  • @Carlo, given as that uses a 3rd-party tool, and the question indicates that "I can't install software on production servers"... Commented Feb 18, 2014 at 16:21
  • Use xslt for that. xsltproc from the package limbxml2-util will do the job Commented Feb 18, 2014 at 16:25
  • @CharlesDuffy you are right, but I thought maybe a cmd line tool was ok, it doesn't bring a whole wagon of dependecies. :) Commented Feb 18, 2014 at 16:30

1 Answer 1

1

Since this isn't valid XML, might as well use sed:

sed -n '
  /<connection-pool /   {s///; s/\/\?>$//; s/ \(initial-limit\|num-cached-statements\)="[^"]*"//g; p} 
  /<connection-factory/ {s///; s/\/\?>$//; s/ \(factory-class\|user\|password\|commit-record-table-name\)="[^"]*"//g; p}
' connections.log | paste -d "" - -
name="name1" max-connections="50" min-connections="5" url="jdbc:oracle:thin:@server1.domain.com:1550:name1"
name="name2" max-connections="50" min-connections="5" url="jdbc:oracle:thin:@server2.domain.com:1524:name2"
name="name3" max-connections="15" min-connections="5" url="jdbc:oracle:thin:@server3.domain.com:1528:name3"
name="name4" max-connections="10" min-connections="1" url="jdbc:oracle:thin:@server4.domain.com:1538:name4"
name="name5" max-connections="10" min-connections="1" url="jdbc:oracle:thin:@//server5.domain.com:1537/name5"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.