Reputation: 169
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!!
Upvotes: 0
Views: 138
Reputation: 247142
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"
Upvotes: 1