Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8528233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:45:23+00:00 2026-06-11T08:45:23+00:00

I have got an xml file containing some attributes like <string name=my/ attribute optional=true>

  • 0

I have got an xml file containing some attributes like

<string name="my/ attribute" optional="true">
  <description>some text</description>
  <value>some text again</value>
</string>

I would like to change the value (which does not necessarily have to be “some text again”) by the string “none”. I tried the following on the command line:

 awk '/<string name="my\/ attribute" optional="true">/,/<\/string>/ {sub(/<value>(.*)<\/value>/,"<value>none</value>")}1' my.xml > my_new.xml

This somehow works ok, but the result is as follows:

<string name="my/ attribute" optional="true">
  <description>some text</description>
  <value>some text again<\/value>
</string>

Why is the / (slash) in the tag escaped?

Thanks a lot for your help,

Daniela.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:45:25+00:00Added an answer on June 11, 2026 at 8:45 am

    Assuming the inconsistencies in your question that Richard pointed out are accidental:

    $ cat input.xml
    <string name="my/ attribute" optional="true">
      <description>some text</description>
      <value>some text again</value>
    </string>
    
    $ awk '/<string/{doit=1} doit{sub(/<value>[^<]+<\/value>/, "<value>none</value>"); print} /<\/string>/{doit=0}' input.xml 
    <string name="my/ attribute" optional="true">
      <description>some text</description>
      <value>none</value>
    </string>
    
    $ 
    

    This is WEE bit safer than your script, in that it will handle minified XML (i.e. whitespace removed, all on e line), but it won’t handle <value> that is split over multiple lines.

    I do recommend looking in to Perl’s XML::Simple or PHP’s SimpleXML. It won’t be a one-liner, but it will work MUCH more reliably.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a huge xml file (~ 85 Mo) and I would like
I have a simple text file containing some CSV with the following structure: @Parent1_Field1,
I've got an XML file on my server, and my partners have to access
I am generating a rss(xml) output form a php file. I have got a
I have got an XML document which looks something like this. <Root> <Info>....</Info> <Info>....</Info>
Hi i have parsed a online xml containing images, I got stuck on parsing
I've got some code to convert a large (many gigabytes) XML file into another
I have got following code witch are sending xml file on HTTP protocol and
I have successfully got annotations from xml file with this: double realLatitude = [[[anns
I've got an XML file which looks somehow like this: <?xml version='1.0' encoding='UTF-8'?> <?xml-stylesheet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.