我不太擅长擦伤,所以我需要有人帮忙。
我有以下输出,我想从以下输出中解析数据:
实际产出:
<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"/>期望产出:
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"如果有人能帮我做这件事,顺便说一句,我会很感激,因为我不能在所有的生产服务器上安装软件。
提前谢谢!!
发布于 2014-02-18 16:48:03
由于这不是有效的XML,所以最好使用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"https://stackoverflow.com/questions/21859383
复制相似问题