Community
    • Login

    Combining Lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 1.1k Views 2 Watching
    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.
    • Katherine CurranK Offline
      Katherine Curran
      last edited by

      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!

      PeterJonesP Alan KilbornA 2 Replies Last reply Reply Quote 0
      • PeterJonesP Online
        PeterJones @Katherine Curran
        last edited by PeterJones

        @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
        • Alan KilbornA Offline
          Alan Kilborn @Katherine Curran
          last edited by Alan Kilborn

          @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

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors