Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Removing line breaks after fixed length

I have a text file with thousands of XML strings on each line. However, if any XML string exceeds 32767 characters, then the remaining text is moved to next line.
I need to remove such line breaks to ensure each line has a complete XML string.

Sample version of the file content having line break after 55 characters is as follows:

<?xml version="1.0" encoding=""?><Policy></Policy>
<?xml version="1.0" encoding=""?><Policy></Policy>
<?xml version="1.0" encoding=""?><Policy>111111111111<
/Policy>
<?xml version="1.0" encoding=""?><Policy></Policy>
<?xml version="1.0" encoding=""?><Policy>2222222222222
</Policy>
<?xml version="1.0" encoding=""?><Policy><A></A>333333
33333</Policy>

The output is expected to be as follows:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<?xml version="1.0" encoding=""?><Policy></Policy>
<?xml version="1.0" encoding=""?><Policy></Policy>
<?xml version="1.0" encoding=""?><Policy>111111111111</Policy>
<?xml version="1.0" encoding=""?><Policy></Policy>
<?xml version="1.0" encoding=""?><Policy>2222222222222</Policy>
<?xml version="1.0" encoding=""?><Policy><A></A>33333333333</Policy>

Please suggest how this can be done in Notepad++

>Solution :

  • Ctrl+H
  • Find what: \R(?!<\?xml)
  • Replace with: LEAVE EMPTY
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • Replace all

Explanation:

\R              # any kind of linebreak
(?!<\?xml)      # negative lookahead, make sure we haven't "<?xml" after

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading