linux - Bash, Remove empty XML tags -
I need to help a few questions using the Bash Tools
- Exempt XML tags from want file:
& lt; CreateOfficeCode & gt; & Lt; OperatorId> Ve & lt; / OperatorId> & Lt; OfficeCode & gt; 1234 & lt; / OfficeCode & gt; & Lt; CountryCodeLength & gt; 0 & lt; / CountryCodeLength & gt; & Lt; AreaCodeLength & gt; 3 & lt; / AreaCodeLength & gt; & Lt; Properties & gt; & Lt; / Properties & gt; & Lt; ChargeArea & gt; & Lt; / ChargeArea & gt; & Lt; / CreateOfficeCode & gt;
To be created:
& lt; CreateOfficeCode & gt; & Lt; OperatorId> Ve & lt; / OperatorId> & Lt; OfficeCode & gt; 1234 & lt; / OfficeCode & gt; & Lt; CountryCodeLength & gt; 0 & lt; / CountryCodeLength & gt; & Lt; AreaCodeLength & gt; 3 & lt; / AreaCodeLength & gt; & Lt; / CreateOfficeCode & gt;
For this, I did this with this command
sed -i '/> & Lt; \ // d 'file
Which is not so strict, the more moves it has, the more appropriate & lt; Pattern & gt; & Lt; / Pattern & gt;
and have to remove it. Suggestion:
- Second, how to go:
& lt; CreateOfficeGroup & gt; & Lt; CreateOfficeName & gt; John & lt; / CreateOfficeName & gt; & Lt; CreateOfficeCode & gt; & Lt; / CreateOfficeCode & gt; & Lt; / CreateOfficeGroup & gt;
to:
& lt; CreateOffice Group & gt; & Lt; CreateOfficeName & gt; John & lt; / CreateOfficeName & gt; & Lt; / CreateOfficeGroup & gt;
- As a whole thing? From:
& lt; CreateOffice Group & gt; & Lt; CreateOfficeName & gt; John & lt; / CreateOfficeName & gt; & Lt; CreateOfficeCode & gt; & Lt; OperatorId> Ve & lt; / OperatorId> & Lt; OfficeCode & gt; 1234 & lt; / OfficeCode & gt; & Lt; CountryCodeLength & gt; 0 & lt; / CountryCodeLength & gt; & Lt; AreaCodeLength & gt; 3 & lt; / AreaCodeLength & gt; & Lt; Properties & gt; & Lt; / Properties & gt; & Lt; ChargeArea & gt; & Lt; / ChargeArea & gt; & Lt; / CreateOfficeCode & gt; & Lt; CreateOfficeSize & gt; & Lt; Chairs & gt; & Lt; / Chairs & gt; & Lt; Tables & gt; & Lt; / Tables & gt; & Lt; / CreateOfficeSize & gt; & Lt; / CreateOfficeGroup & gt;
to:
& lt; CreateOffice Group & gt; & Lt; CreateOfficeName & gt; John & lt; / CreateOfficeName & gt; & Lt; CreateOfficeCode & gt; & Lt; OperatorId> Ve & lt; / OperatorId> & Lt; OfficeCode & gt; 1234 & lt; / OfficeCode & gt; & Lt; CountryCodeLength & gt; 0 & lt; / CountryCodeLength & gt; & Lt; AreaCodeLength & gt; 3 & lt; / AreaCodeLength & gt; & Lt; / CreateOfficeCode & gt; & Lt; / CreateOfficeGroup & gt;
Can you answer the questions as a person? Thanks a lot!
sed '# 1 hour; 1 $ H: $$ x: Remtag s # \ (\ n * * *) * & lt; \ ([^ & Gt;] * & gt; \) \ (* \ n * *) * & lt; / \ 2 ## gt Remit P} 'Your File
( - posix
on GOO SAD
- The empty tag happens.
- Not an XML parser, something like
& lt; tag1 prop = "& lt; tag2 >
Comments
Post a Comment