Loading ...
Sorry, an error occurred while loading the content.

Deleting multiple lines

Expand Messages
  • John Shotsky
    I have a situation where I d like to delete several lines between two delimiters, multiple times in a file, in addition to leading and trailing stuff that I
    Message 1 of 5 , May 3, 2009
    • 0 Attachment
      I have a situation where I'd like to delete several lines between two delimiters, multiple times in a file, in addition
      to leading and trailing 'stuff' that I don't need.

      Input:
      Start of file
      Lines to delete
      [[[
      Lines to keep
      ]]]
      Any number of lines to be deleted
      [[[
      Lines to keep
      ]]]
      Several lines to delete
      [[[
      More lines to keep
      ]]]
      More lines to delete
      eof

      Any ideas?
      Thanks!
      John




      [Non-text portions of this message have been removed]
    • Alec Burgess
      John Shotsky (jshotsky@comcast.net) wrote (in part) (on 2009-05-04 at ... H= KeepBetweenDelims ^!set %theSearch%= (?sm)( [{3} r n(.*?) r n ]{3}) ^!Set
      Message 2 of 5 , May 4, 2009
      • 0 Attachment
        John Shotsky (jshotsky@...) wrote (in part) (on 2009-05-04 at
        00:06):
        > I have a situation where I'd like to delete several lines between two
        > delimiters, multiple times in a file, in addition
        > to leading and trailing 'stuff' that I don't need.
        >
        > Input:
        > Start of file
        > Lines to delete
        > [[[
        > Lines to keep
        > ]]]
        > Any number of lines to be deleted
        > [[[
        > Lines to keep
        > ]]]
        > Several lines to delete
        > [[[
        > More lines to keep
        > ]]]
        > More lines to delete
        > eof

        H="KeepBetweenDelims"
        ^!set %theSearch%="(?sm)(\[{3}\r\n(.*?)\r\n\]{3})"
        ^!Set %allMatches%=^$GetDocListAll("^%theSearch%";"$2^P")$
        ;^!info ^%allMatches%
        ^!select ALL
        ^!inserttext ^%allMatches%

        Note: ^$GetDocListAll()$ and ^$GetDocReplaceAll() were added in 5.7 -
        Prior to them I wasted a lot of time trying to construct regexs that
        would remove unwanted "stuff" by trying to use lookaheads and
        lookbehinds etc.

        These functions - especially ^$GetDocListAll()$ make it easy to find and
        format all the "wanted" stuff - then just replace the entire file with
        the constructed replacement.

        If you want to keep the delimeters as well, change "$2^P" to "$1^P"

        --
        Regards ... Alec (buralex@gmail & WinLiveMess - alec.m.burgess@skype)




        [Non-text portions of this message have been removed]
      • Flo
        ... ^!SetClipboard ^$GetDocListAll( (?s) [ [ [.+? ] ] ] ; $0 r n )$ ^!Toolbar Paste New Flo
        Message 3 of 5 , May 4, 2009
        • 0 Attachment
          --- In ntb-clips@yahoogroups.com, "John Shotsky" <jshotsky@...> wrote:
          >
          > I have a situation where I'd like to delete several lines between two delimiters, multiple times in a file, in addition
          > to leading and trailing 'stuff' that I don't need.
          >
          > Input:
          > Start of file
          > Lines to delete
          > [[[
          > Lines to keep
          > ]]]
          > Any number of lines to be deleted
          > [[[
          > Lines to keep
          > ]]]
          > Several lines to delete
          > [[[
          > More lines to keep
          > ]]]
          > More lines to delete
          > eof
          >
          > Any ideas?
          > Thanks!
          > John

          ^!SetClipboard ^$GetDocListAll("(?s)\[\[\[.+?\]\]\]";"$0\r\n")$
          ^!Toolbar Paste New

          Flo
        • John Shotsky
          Thanks! I did figure out a way to do it, by placing fake delimiters at the beginning and end of the file, then using a find, a replace, then removing the
          Message 4 of 5 , May 4, 2009
          • 0 Attachment
            Thanks!

            I did figure out a way to do it, by placing 'fake' delimiters at the beginning and end of the file, then using a find, a
            replace, then removing the fake delimiters.

            This looks far easier. I haven't played around with GetDocList yet, so I will look into it.

            John

            From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of Flo
            Sent: Monday, May 04, 2009 3:34 AM
            To: ntb-clips@yahoogroups.com
            Subject: [Clip] Re: Deleting multiple lines





            --- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com> , "John Shotsky" <jshotsky@...> wrote:
            >
            > I have a situation where I'd like to delete several lines between two delimiters, multiple times in a file, in
            addition
            > to leading and trailing 'stuff' that I don't need.
            >
            > Input:
            > Start of file
            > Lines to delete
            > [[[
            > Lines to keep
            > ]]]
            > Any number of lines to be deleted
            > [[[
            > Lines to keep
            > ]]]
            > Several lines to delete
            > [[[
            > More lines to keep
            > ]]]
            > More lines to delete
            > eof
            >
            > Any ideas?
            > Thanks!
            > John

            ^!SetClipboard ^$GetDocListAll("(?s)\[\[\[.+?\]\]\]";"$0\r\n")$
            ^!Toolbar Paste New

            Flo



            [Non-text portions of this message have been removed]
          • John Shotsky
            Thanks, Alec, I ll look into that GetDocListAll command. Below is my rather kludgey way of doing it.added fake delimiters, performed a replace, removed the
            Message 5 of 5 , May 4, 2009
            • 0 Attachment
              Thanks, Alec, I'll look into that GetDocListAll command. Below is my rather kludgey way of doing it.added fake
              delimiters, performed a replace, removed the fakes. It works, and it's fast, but obviously it is inelegant.

              ^!Jump Doc_End
              ^!InsertText [[[E
              ^!Jump Doc_Start
              ^!InsertText S]]]
              ^!Jump Doc_Start
              :DumpEmail
              ^!Find "(?s)\]\]\].+?\[\[\[" RS
              ^!IfError EmailDumped
              ^!Replace "(?s)(S?\]\]\]).+?(\[\[\[E?)" >> "$1\n\n$2" RAWS0
              ^!Jump Select_End
              ^!Jump +1
              ^!Goto DumpEmail
              :EmailDumped
              ^!Replace "(\[\[\[E|S\]\]\])" >> "" RAWS0

              John

              From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of Alec Burgess
              Sent: Monday, May 04, 2009 12:20 AM
              To: ntb-clips@yahoogroups.com
              Subject: Re: [Clip] Deleting multiple lines






              John Shotsky (jshotsky@... <mailto:jshotsky%40comcast.net> ) wrote (in part) (on 2009-05-04 at
              00:06):
              > I have a situation where I'd like to delete several lines between two
              > delimiters, multiple times in a file, in addition
              > to leading and trailing 'stuff' that I don't need.
              >
              > Input:
              > Start of file
              > Lines to delete
              > [[[
              > Lines to keep
              > ]]]
              > Any number of lines to be deleted
              > [[[
              > Lines to keep
              > ]]]
              > Several lines to delete
              > [[[
              > More lines to keep
              > ]]]
              > More lines to delete
              > eof

              H="KeepBetweenDelims"
              ^!set %theSearch%="(?sm)(\[{3}\r\n(.*?)\r\n\]{3})"
              ^!Set %allMatches%=^$GetDocListAll("^%theSearch%";"$2^P")$
              ;^!info ^%allMatches%
              ^!select ALL
              ^!inserttext ^%allMatches%

              Note: ^$GetDocListAll()$ and ^$GetDocReplaceAll() were added in 5.7 -
              Prior to them I wasted a lot of time trying to construct regexs that
              would remove unwanted "stuff" by trying to use lookaheads and
              lookbehinds etc.

              These functions - especially ^$GetDocListAll()$ make it easy to find and
              format all the "wanted" stuff - then just replace the entire file with
              the constructed replacement.

              If you want to keep the delimeters as well, change "$2^P" to "$1^P"

              --
              Regards ... Alec (buralex@gmail & WinLiveMess - alec.m.burgess@skype)

              [Non-text portions of this message have been removed]



              [Non-text portions of this message have been removed]
            Your message has been successfully submitted and would be delivered to recipients shortly.