Navigation

    Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Copying contents between a specific string and a character

    Help wanted · · · – – – · · ·
    3
    4
    949
    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.
    • Viktoria Ontapado
      Viktoria Ontapado last edited by

      Hi All!
      I’d like to request a bit of help with the following.
      I have a text-file (converted from an e-book) with a structure like this:


      9/Maywood

      Description of the band, stories and anecdotes about them, etc.

      Albums:
      1983 - Het beste van Maywood
      1987 - Beside You
      1990 - Achter De Horizon
      1991 - 6 Of The Thirties

      10/Talking Heads

      Description of the band, stories and anecdotes about them, etc.

      Albums:
      Fear of Music (1979)
      Remain in Light (1980)

      11/Sly and the Family Stone

      Description of the band, stories and anecdotes about them, etc.

      Albums:
      1968: Life
      1969: Stand!
      1971: There’s a Riot Goin’ On

      12/Delaney & Bonnie

      Description of the band, stories and anecdotes about them, etc.

      Albums:
      To Bonnie from Delaney - Atco, 1970
      Motel Shot - Atco, 1971
      Country Life - Atco, 1972
      D&B Together - Columbia, 1972

      13/Mother’s Finest

      Description of the band, stories and anecdotes about them, etc.

      Albums:
      Iron Age (1981), Atlantic

      14/INXS

      Description of the band, stories and anecdotes about them, etc.

      Albums:
      Shabooh Shoobah (1982)
      The Swing (1984)
      Listen Like Thieves (1985)

      and so on…containing approx. 800 bands.


      I need a file containing only the albums ("Albums:’ line included) uninterruptedly in the following format:

      Albums:
      1983 - Het beste van Maywood
      1987 - Beside You
      1990 - Achter De Horizon
      1991 - 6 Of The Thirties
      Albums:
      Fear of Music (1979)
      Remain in Light (1980)
      Albums:
      1968: Life
      1969: Stand!
      1971: There’s a Riot Goin’ On
      Albums:
      To Bonnie from Delaney - Atco, 1970
      Motel Shot - Atco, 1971
      Country Life - Atco, 1972
      D&B Together - Columbia, 1972
      Albums:
      Iron Age (1981), Atlantic
      Albums:
      Shabooh Shoobah (1982)
      The Swing (1984)
      Listen Like Thieves (1985)
      .
      .
      .

      What way can I achieve this?
      So the line “Albums:” is constant in the original file and every page starts with page number/band so slash is steadily presented as well.

      I guess somehow we can copy the texts between these two and go from there?

      Thank you so much and have a nice day,
      Viktoria

      Scott Sumner 1 Reply Last reply Reply Quote 2
      • Scott Sumner
        Scott Sumner @Viktoria Ontapado last edited by

        @Viktoria-Ontapado

        Using the technique from @guy038 in this thread; specifically:

        SEARCH : (?s).*?(Your Regex)|.*

        and substituting

        ?:^(Albums:\R.*?\R)\R into it for Your Regex

        I was able to arrive at your desired result.

        So, in summary:

        Find what zone: (?s).*?(?:^(Albums:\R.*?\R)\R)|.*
        Replace with zone: \1
        Search mode: Regular expression
        Action: Replace or Replace All
        Note: This is a destructive replacement, not a copy, so if you need the original data, make a copy of it first and then perform this operation on the copy.

        BTW, very nice sample data and discussion about what you wanted!

        1 Reply Last reply Reply Quote 1
        • guy038
          guy038 last edited by guy038

          Hello, @viktoria-ontapado, and All,

          Again, easy task with the help of regular expressions ;-))

          From your example, seemingly, the areas of text to delete must :

          • Begins after two consecutive line breaks ( CR LF CR LF ), so the regex \R\R

          • Ends right before the string Albums:, beginning a line, so the look-ahead (?=\RAlbums)

          • In between, we have to select the shortest range of any character(s), between these boundaries, even split on several lines, so the regex (?s).*?


          So :

          • Possibly, add two lines breaks, at the very beginning of your list

          • Open the Replace dialog ( Ctrl + H )

          SEARCH \R\R(?s).*?(?=\RAlbums:)

          REPLACE Leave EMPTY

          • Select the Regular expression search mode

          • Set the Wrap around option

          • Click, once on the Replace All button OR several times on the Replace button

          Et voilà !


          So, given your list, below :

          
          
          9/Maywood
          
          Description of the band, stories and anecdotes about them, etc.
          
          Albums:
          1983 - Het beste van Maywood
          1987 - Beside You
          1990 - Achter De Horizon
          1991 - 6 Of The Thirties
          
          10/Talking Heads
          
          Description of the band, stories and anecdotes about them, etc.
          
          Albums:
          Fear of Music (1979)
          Remain in Light (1980)
          
          11/Sly and the Family Stone
          
          Description of the band, stories and anecdotes about them, etc.
          
          Albums:
          1968: Life
          1969: Stand!
          1971: There’s a Riot Goin’ On
          
          12/Delaney & Bonnie
          
          Description of the band, stories and anecdotes about them, etc.
          
          Albums:
          To Bonnie from Delaney - Atco, 1970
          Motel Shot - Atco, 1971
          Country Life - Atco, 1972
          D&B Together - Columbia, 1972
          
          13/Mother’s Finest
          
          Description of the band, stories and anecdotes about them, etc.
          
          Albums:
          Iron Age (1981), Atlantic
          
          14/INXS
          
          Description of the band, stories and anecdotes about them, etc.
          
          Albums:
          Shabooh Shoobah (1982)
          The Swing (1984)
          Listen Like Thieves (1985)
          

          You should get the expected text :

          
          Albums:
          1983 - Het beste van Maywood
          1987 - Beside You
          1990 - Achter De Horizon
          1991 - 6 Of The Thirties
          Albums:
          Fear of Music (1979)
          Remain in Light (1980)
          Albums:
          1968: Life
          1969: Stand!
          1971: There’s a Riot Goin’ On
          Albums:
          To Bonnie from Delaney - Atco, 1970
          Motel Shot - Atco, 1971
          Country Life - Atco, 1972
          D&B Together - Columbia, 1972
          Albums:
          Iron Age (1981), Atlantic
          Albums:
          Shabooh Shoobah (1982)
          The Swing (1984)
          Listen Like Thieves (1985)
          

          Best Regards,

          guy038

          P.S. :

          Viktoria, I’ve just realized that Scott already gave you a solution ! Anyway, I do agree with the last sentence of his reply, too !

          1 Reply Last reply Reply Quote 1
          • Viktoria Ontapado
            Viktoria Ontapado last edited by

            As usual, I really appreciate the answers, thank you so much to both of you for the solutions, explanations.
            The link to the other thread is invaluable as well to me, cheers for that.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Copyright © 2014 NodeBB Forums | Contributors