• Login
Community
  • Login

Combining Lines

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 3 Posters 390 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K
    Katherine Curran
    last edited by Aug 17, 2022, 2:44 PM

    Hello,

    I am looking to condense a transcript that currently breaks up a speaker’s words into multiple lines:

    John Doe: Hello.

    John Doe: How are you today?

    John Doe: I hope that you are well.

    I would like to condense the lines into one resulting in the following:

    John Doe: Hello. How are you today? I hope that you are well.

    Is there a way to do this by removing the line breaks and the speaker’s name?

    Thank you!

    P A 2 Replies Last reply Aug 17, 2022, 5:09 PM Reply Quote 0
    • P
      PeterJones @Katherine Curran
      last edited by PeterJones Aug 17, 2022, 5:11 PM Aug 17, 2022, 5:09 PM

      @Katherine-Curran said in Combining Lines:

      Is there a way to do this by removing the line breaks and the speaker’s name?

      Using regular expression search mode, yes

      • FIND = (?-s)^(.*?: )(.*?)\R+(\1)
        • this says match up to the colon and space of the name, and store that as group 1; save the rest of the line as group2, match one or more newlines, and then see if the next non-blank line is the same as the previous speaker’s name
      • REPLACE = $1$2\x20
        • the $1$2 are the values of the two matched groups
        • the \x20 is equivalent to a space, but easier to copy/paste from the forum
        • so replaces the old name/text/newlines/name with name/text/space, effectively doing what you wanted
      • MODE = regular expression
      • run REPLACE ALL until it finishes (shows 0 replacements)

      (there are even more complicated regex that would allow with only one REPLACE ALL, but the amount of time it takes to debug those super-fancy regex far outweigh the time to hit REPLACE ALL 3-4 times)
      ----

      Useful References

      • Please Read Before Posting
      • Template for Search/Replace Questions
      • FAQ: Where to find regular expressions (regex) documentation
      • Notepad++ Online User Manual: Searching/Regex
      1 Reply Last reply Reply Quote 0
      • A
        Alan Kilborn @Katherine Curran
        last edited by Alan Kilborn Aug 17, 2022, 5:11 PM Aug 17, 2022, 5:10 PM

        @Katherine-Curran

        Find: (?-s)^(.+?):(.+)\R\1:(.+)
        Replace: ${1}:${2}${3}
        Wrap around: ticked
        Search mode: Regular expression
        Press Replace All repeatedly until the status bar of the Replace window indicates 0 replacements made

        Example:

        John Doe: Hello.
        John Doe: How are you today?
        John Doe: I hope that you are well.
        Bob Doe: Hello.
        Bob Doe: How are you today?
        Bob Doe: I hope that you are well.
        John Doe: Hello.
        John Doe: How are you today?
        John Doe: I hope that you are well.
        

        After the first Replace All press:

        John Doe: Hello. How are you today?
        John Doe: I hope that you are well.
        Bob Doe: Hello. How are you today?
        Bob Doe: I hope that you are well.
        John Doe: Hello. How are you today?
        John Doe: I hope that you are well.
        

        Status bar indicates 3 replacements made.

        After the second Replace All press:

        John Doe: Hello. How are you today? I hope that you are well.
        Bob Doe: Hello. How are you today? I hope that you are well.
        John Doe: Hello. How are you today? I hope that you are well.
        

        Status bar indicates 3 replacements made.

        After the third Replace All press:

        John Doe: Hello. How are you today? I hope that you are well.
        Bob Doe: Hello. How are you today? I hope that you are well.
        John Doe: Hello. How are you today? I hope that you are well.
        

        Status bar indicates 0 replacements made. (Data transform was actually complete with the previous press, but that can only be determined via visual inspection).

        1 Reply Last reply Reply Quote 1
        3 out of 3
        • First post
          3/3
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors