我需要一些帮助,使用bash工具解决几个问题
<CreateOfficeCode> <OperatorId>ve</OperatorId> <OfficeCode>1234</OfficeCode> <CountryCodeLength>0</CountryCodeLength> <AreaCodeLength>3</AreaCodeLength> <Attributes></Attributes> <ChargeArea></ChargeArea> </CreateOfficeCode>
成为:
<CreateOfficeCode> <OperatorId>ve</OperatorId> <OfficeCode>1234</OfficeCode> <CountryCodeLength>0</CountryCodeLength> <AreaCodeLength>3</AreaCodeLength> </CreateOfficeCode>
为此,我已经通过此命令这样做
sed -i '/><\//d' file
并不是那么严格,它更像是一个把戏,更合适的方法是找到<pattern></pattern>并删除它。建议?
<pattern></pattern>
<CreateOfficeGroup> <CreateOfficeName>John</CreateOfficeName> <CreateOfficeCode> </CreateOfficeCode> </CreateOfficeGroup>
至:
<CreateOfficeGroup> <CreateOfficeName>John</CreateOfficeName> </CreateOfficeGroup>
<CreateOfficeGroup> <CreateOfficeName>John</CreateOfficeName> <CreateOfficeCode> <OperatorId>ve</OperatorId> <OfficeCode>1234</OfficeCode> <CountryCodeLength>0</CountryCodeLength> <AreaCodeLength>3</AreaCodeLength> <Attributes></Attributes> <ChargeArea></ChargeArea> </CreateOfficeCode> <CreateOfficeSize> <Chairs></Chairs> <Tables></Tables> </CreateOfficeSize> </CreateOfficeGroup>
<CreateOfficeGroup> <CreateOfficeName>John</CreateOfficeName> <CreateOfficeCode> <OperatorId>ve</OperatorId> <OfficeCode>1234</OfficeCode> <CountryCodeLength>0</CountryCodeLength> <AreaCodeLength>3</AreaCodeLength> </CreateOfficeCode> </CreateOfficeGroup>
您可以个人回答问题吗?非常感谢你!
sed '#n 1h;1!H $ { x :remtag s#\(\n* *\)*<\([^>]*>\)\( *\n*\)*</\2##g t remtag p }' YourFile
(posix版本--posix,例如GNU sed)
--posix
<tag1 prop="<tag2></tag2>"> ...