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

  • SEARCH
  • Home
  • 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 6725701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:50:20+00:00 2026-05-26T09:50:20+00:00

I´m currently working on a short SED script that needs to HTML-encode parts of

  • 0

I´m currently working on a short SED script that needs to HTML-encode parts of an XML-file. The script currently looks like this:

sed.exe "/<messageData>/,/<\/messageData>/ {/<messageData>/b;/<\/messageData>/b; s/</\&lt;/g; s/>/\&gt;/g; }" %1 >%2

So basically, replace all < and > with < and > , between the and tags.

This script works perfectly well with pretty printed XML, that is

<?xml version="1.0" encoding="ISO-8859-1"?>
<Messages>
    <messageData>
        <test>DATA</test>
    </messageData>
</Messages>

comes out as

<?xml version="1.0" encoding="ISO-8859-1"?>
<Messages>
    <messageData>
        &lt;test&gt;DATA&lt;/test&gt;
    </messageData>
</Messages>

which is what I need. My issue is that the files I need process is not pretty printed, everything is on a single line, like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Messages><messageData><test>DATA</test></messageData></Messages>

And with this format, the script no longer works.
Would it be possibly to modify my script to work with both formats?

Please note that I´m not able to affect the output format, and that SED is the scripting engine to be used.

I guess I could just create another SED script that would insert a line-break after each > in the file, and after that run the script that I have created now. However I´m guessing that would not be very efficient performance wise (two passes over each file).

Any suggestions?

Regards
Daniel

  • 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-05-26T09:50:20+00:00Added an answer on May 26, 2026 at 9:50 am

    In case someone happens to stumble on the same issue, this is how we solved it. I know it´s not pretty, be it will have to do until we can use a better solution.

    sed.exe -i "s/\(>\)\(<\)/\1\n\2/g" %1
    sed.exe "/<messageData>/,/<\/messageData>/ {/<messageData>/b;/<\/messageData>/b; s/</\&lt;/g; s/>/\&gt;/g; }" %1 >%2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The project I'm currently working on needs to interface with a client system that
I'm currently working on a very short project on Prolog, and just got stuck
I'm currently working on a small short-lived project. But despite the size it's complicated
I'm currently working on wholesale online t-shirt shop. I have done this for fixed
I'm working on a program that will sort files based on extension I currently
Am currently working on an application that requires users to submit posts and comments
The website that I'm currently working on is having a few issues with Webkit
I am currently working on a web app that will replace old systems in
I'm currently working with some data using Javascript that is in the form of
I'm currently working on a problem that requires the random selection of an element

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.