iceman225
iceman225

Reputation: 109

Sed insert value when matching pattern

i have a xml file and i need to insert a value contains in a variable between PurchaseOrderNumber="99503". For exemple if $value=001 i will have PurchaseOrderNumber="00199503". I tried many commands with sed but nothing work the last one i tried is sed '/^PurchaseOrderNumber=\"/s/^/001/' file.xml > output.xml can you help me on that

 <?xml version="1.0"?>

        <PurchaseOrder PurchaseOrderNumber="99503" OrderDate="1999-10-20">
          <Address Type="Shipping">
            <Name>Ellen Adams</Name>
            <Street>123 Maple Street</Street>
            <City>Mill Valley</City>
            <State>CA</State>
            <Zip>10999</Zip>
            <Country>USA</Country>
          </Address>
          <Address Type="Billing">
            <Name>Tai Yee</Name>
            <Street>8 Oak Avenue</Street>
            <City>Old Town</City>
            <State>PA</State>
            <Zip>95819</Zip>
            <Country>USA</Country>
          </Address>
     </PurchaseOrder>

Upvotes: 0

Views: 67

Answers (3)

iceman225
iceman225

Reputation: 109

thank's that work, i also found a way so i post it if it's can help anyone

sed 's/PurchaseOrderNumber=\"/&001/' file.xml > output.xml

Upvotes: 0

pelya
pelya

Reputation: 4494

sed 's/PurchaseOrderNumber="/PurchaseOrderNumber="001/g'

Also, read this.

Upvotes: 2

choroba
choroba

Reputation: 241828

Use a proper XML handling tool to process XML. For example, I used xsh:

open file.xml ;
insert text '001' prepend /PurchaseOrder/@PurchaseOrderNumber ;
save :b ;

Upvotes: 1

Related Questions