-1

I have a text file with the following text. There is a line break for many of the rows in this file.

I need to use backspace and join with the previous line text for the line which starts with your

            1023456;jjdss.D.djDJ;2345;for your account;BR
            2345678;jjdss.D.djDJ;2345;for your account;BR
            4567891;jjdss.D.djDJ;2345;for
             your account;BR
            2345678;jjdss.D.djDJ;2345;for your account;BR
            1023456;jjdss.D.djDJ;2345;for your account;BR
            4567891;jjdss.D.djDJ;2345;for
             your account;BR
            4567891;jjdss.D.djDJ;2345;for
             your account;BR

The desired result

              1023456;jjdss.D.djDJ;2345;for your account;BR
              2345678;jjdss.D.djDJ;2345;for your account;BR
              4567891;jjdss.D.djDJ;2345;for your account;BR
              2345678;jjdss.D.djDJ;2345;for your account;BR
              1023456;jjdss.D.djDJ;2345;for your account;BR
              4567891;jjdss.D.djDJ;2345;for your account;BR
              4567891;jjdss.D.djDJ;2345;for your account;BR

I have used notepad++ macro to do this but the results was a single line of text with all the 1000 lines in the file.

ANy help would be appreciated

David Faber
  • 11,549
  • 2
  • 25
  • 40
sshr
  • 145
  • 1
  • 7

1 Answers1

0

If you wanted to use a regex, I'd approach it by capturing all instances of 'for' with a newline or carriage return following it and replace these with 'for '.

For example, if with I were to approach your problem in JavaScript I would use the following:

var str = `1023456;jjdss.D.djDJ;2345;for your account;BR
            2345678;jjdss.D.djDJ;2345;for your account;BR
            4567891;jjdss.D.djDJ;2345;for
             your account;BR
            2345678;jjdss.D.djDJ;2345;for your account;BR
            1023456;jjdss.D.djDJ;2345;for your account;BR
            4567891;jjdss.D.djDJ;2345;for
             your account;BR
            4567891;jjdss.D.djDJ;2345;for
             your account;BR`;

var regex = /(for(\n|\r))/gm;

var res = str.replace(regex, 'for ');

This would result in:

1023456;jjdss.D.djDJ;2345;for your account;BR
2345678;jjdss.D.djDJ;2345;for your account;BR
4567891;jjdss.D.djDJ;2345;for your account;BR
2345678;jjdss.D.djDJ;2345;for your account;BR
1023456;jjdss.D.djDJ;2345;for your account;BR
4567891;jjdss.D.djDJ;2345;for your account;BR
4567891;jjdss.D.djDJ;2345;for your account;BR

I've created a fiddle to illustrate this.

If you are looking to get some more experience in regex there are some great answers out there to help you along, such as this one which does a good job of explaining them as well as linking to some useful resources.

joesch
  • 347
  • 1
  • 4
  • 16