Unix - Uncomment xml comments
我在XML文件中有下面的节点。如何使用Unix Shell脚本或命令取消对mainHost首次出现的注释?
1 2 3 4 5 6 7 8 | <!-- Host without authentication --> <!-- <mainHost> <hostName>test.com</hostName> <httpPort>80</httpPort> </mainHost> --> <!-- Host with authentication userId: User name of Host server Password: --> <!-- <mainHost> <hostName>127.0.0.1</hostName> <httpPort>80</httpPort> <userId>username</userId> <password>password</password> </mainHost> --> |
我尝试使用以下命令进行各种更改,但这似乎不起作用。
sed'0,/ <!-/ {s / <!-//}'/test.xml
我期望低于输出
1 2 3 4 5 6 7 8 | <!-- Host without authentication --> <mainHost> <hostName>test.com</hostName> <httpPort>80</httpPort> </mainHost> <!-- Host with authentication userId: User name of Host server Password: --> <!-- <mainHost> <hostName>127.0.0.1</hostName> <httpPort>80</httpPort> <userId>username</userId> <password>password</password> </mainHost> --> |
谢谢
您处在正确的Rails上(假设必须使用
创建具有以下内容的文件(例如
1 2 3 4 5 6 | 0,/<\\/mainHost>/{ /<mainHost>/,/<\\/mainHost>/{ s/<!--// s/-->// } } |
并运行
请注意,此解决方案很难一概而论。