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

Re: [Clip] Remove a line

Expand Messages
  • Axel Berger
    ... No solution, just a rough outline of one. First sort lines. Then find consecutive lines with identical first seven characters and delete the second. Go
    Message 1 of 17 , Jan 17, 2012
      bozlawless wrote:
      > I need a clip to search a document and remove ALL of the
      > duplicate lines LEAVING ONLY ONE based on the first word
      > or code in this case

      No solution, just a rough outline of one. First sort lines. Then find
      consecutive lines with identical first seven characters and delete the
      second. Go back one line and loop.

      See Regex -> Repetition -> Back References for how to find two identical
      strings.

      Off now, back in the early evening, German time.

      Axel

      --
      Dipl.-Ing. F. Axel Berger Tel: +49/ 2174/ 7439 07
      Johann-Häck-Str. 14 Fax: +49/ 2174/ 7439 68
      D-51519 Odenthal-Heide eMail: Axel-Berger@...
      Deutschland (Germany) http://berger-odenthal.de
    • John Shotsky
      This should do what you want. ^!Replace (?s)^( w{7}).+? R.* K 1.+? R AIRSW ^!IfError Next Else Skip_-1 Sorting is not mandatory, but could be added.
      Message 2 of 17 , Jan 17, 2012
        This should do what you want.
        ^!Replace "(?s)^(\w{7}).+?\R.*\K\1.+?\R" >> "" AIRSW
        ^!IfError Next Else Skip_-1

        Sorting is not mandatory, but could be added.

        Regards,
        John
        RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/

        From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of bozlawless
        Sent: Tuesday, January 17, 2012 03:03
        To: ntb-clips@yahoogroups.com
        Subject: [Clip] Remove a line


        I need a clip to search a document and remove ALL of the duplicate lines LEAVING ONLY ONE based on the first word or
        code in this case

        example
        GC31R7K,2012-01-13T18:37Z,Found it,"" (example)
        GC31R7K,2012-01-13T18:37Z,Found it,"" (remove this line)
        GC31R6G,2012-01-13T18:38Z,Found it,"" (example)
        GC31R3C,2012-01-13T18:38Z,Found it,""
        GC31R7M,2012-01-13T18:39Z,Found it,""
        GC31R6B,2012-01-13T18:40Z,Found it,""
        GC31R7Q,2012-01-13T18:40Z,Found it,""
        GC31R7P,2012-01-13T18:41Z,Found it,""
        GC31R39,2012-01-13T18:42Z,Found it,""
        GC31R3A,2012-01-13T18:42Z,Found it,""
        GC31R7K,2012-01-13T18:37Z,Found it,"" (remove this line)
        GC31R2Q,2012-01-13T18:42Z,Found it,""
        GC31R2M,2012-01-13T18:43Z,Found it,""
        GC31R6C,2012-01-13T18:44Z,Found it,""
        GC31R6G,2012-01-13T18:38Z,Found it,"" (remove this line)
        GC31R7H,2012-01-13T18:44Z,Found it,""
        GC31R6D,2012-01-13T18:45Z,Found it,""
        GC31R6F,2012-01-13T18:45Z,Found it,""
        GC31R34,2012-01-13T18:47Z,Found it,""
        GC31R6H,2012-01-13T18:52Z,Found it,""
        GC31R6J,2012-01-13T18:52Z,Found it,""
        GC31R6G,2012-01-13T18:38Z,Found it,"" (remove this line)
        GC31R6K,2012-01-13T18:53Z,Found it,""
        GC31R6M,2012-01-13T18:53Z,Found it,""
        GC31R6P,2012-01-13T18:54Z,Found it,""



        [Non-text portions of this message have been removed]
      • Don
        ... John, What are the odds you could explain that for us :-) Is it removing the first instance and leaving the latter instance intact?
        Message 3 of 17 , Jan 17, 2012
          On 1/17/2012 8:31 AM, John Shotsky wrote:
          > This should do what you want.
          > ^!Replace "(?s)^(\w{7}).+?\R.*\K\1.+?\R" >> "" AIRSW
          > ^!IfError Next Else Skip_-1
          >
          > Sorting is not mandatory, but could be added.
          >
          > Regards,
          > John

          John,

          What are the odds you could explain that for us :-)
          Is it removing the first instance and leaving the latter instance intact?
        • John Shotsky
          The (?s) means multiline search, so it will search without regard to line ends. The w{7} means the first 7 letters and/or numbers. The parens around the above
          Message 4 of 17 , Jan 17, 2012
            The (?s) means multiline search, so it will search without regard to line ends.
            The \w{7} means the first 7 letters and/or numbers.
            The parens around the above line makes it capture with a reference back to it of \1
            The .* means to skip through everything looking for the match.
            the \K means to keep everything before the \K.
            The \1 refers to that first capture, meaning it is a duplicate of the first 7 characters captured earlier.
            The rest of it captures that whole line, and the replacement keeps all before the \K and loses what follows � the
            duplicate line.
            The next line is a loop to keep repeating the replace until there are no duplicates left.

            Regards,
            John
            RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/

            From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of Don
            Sent: Tuesday, January 17, 2012 06:42
            To: ntb-clips@yahoogroups.com
            Subject: Re: [Clip] Remove a line


            On 1/17/2012 8:31 AM, John Shotsky wrote:
            > This should do what you want.
            > ^!Replace "(?s)^(\w{7}).+?\R.*\K\1.+?\R" >> "" AIRSW
            > ^!IfError Next Else Skip_-1
            >
            > Sorting is not mandatory, but could be added.
            >
            > Regards,
            > John

            John,

            What are the odds you could explain that for us :-)
            Is it removing the first instance and leaving the latter instance intact?



            [Non-text portions of this message have been removed]
          • loro
            ... Does that mean the whole lines don t need to be identical? Because for the case when the whole lines are identical there s a built in option. ... Options |
            Message 5 of 17 , Jan 17, 2012
              bozlawless wrote:
              >I need a clip to search a document and remove ALL of the duplicate
              >lines LEAVING ONLY ONE based on the first word or code in this case

              Does that mean the whole lines don't need to be identical? Because
              for the case when the whole lines are identical there's a built in option.
              --------------
              Options | Tools | Sort Removes Duplicates
              Removes duplicate lines encountered by the sorting function.
              --------------

              And the referred to sorting function is at Modify | Lines | Sort .

              Lotta
            • flo.gehrke
              ... This doesn t remove a duplicate at the end of the list (with no trailing empty line). To achieve this, try... ^!Replace (^ w{7}) X+? K 1 X+?( R| Z)
              Message 6 of 17 , Jan 17, 2012
                --- In ntb-clips@yahoogroups.com, "John Shotsky" <jshotsky@...> wrote:
                >
                > This should do what you want.
                > ^!Replace "(?s)^(\w{7}).+?\R.*\K\1.+?\R" >> "" AIRSW
                > ^!IfError Next Else Skip_-1
                >
                > Sorting is not mandatory, but could be added.
                >
                > Regards,
                > John

                This doesn't remove a duplicate at the end of the list (with no trailing empty line). To achieve this, try...

                ^!Replace "(^\w{7})\X+?\K\1\X+?(\R|\Z)" >> "" AWRS
                ^!IfError End Else Skip_-1

                Regards,
                Flo
              • Don
                ... 1.+? R means match the back-referenced first seven characters, plus whatever that completes a line. The ? means not greedy I think. But could that
                Message 7 of 17 , Jan 17, 2012
                  On 1/17/2012 10:00 AM, John Shotsky wrote:
                  > The (?s) means multiline search, so it will search without regard to line ends.
                  > The \w{7} means the first 7 letters and/or numbers.
                  > The parens around the above line makes it capture with a reference back to it of \1
                  > The .* means to skip through everything looking for the match.
                  > the \K means to keep everything before the \K.
                  > The \1 refers to that first capture, meaning it is a duplicate of the first 7 characters captured earlier.
                  > The rest of it captures that whole line, and the replacement keeps all before the \K and loses what follows – the
                  > duplicate line.
                  > The next line is a loop to keep repeating the replace until there are no duplicates left.
                  >
                  > Regards,
                  > John

                  \1.+?\R
                  means match the "back-referenced" first seven characters, plus whatever
                  that completes a line. The ? means not greedy I think.

                  But could that back-reference occur mid-line in this? Or is the ^
                  meaning line start somehow implicitly carried forward?
                • John Shotsky
                  I thought of that later. In my own clip library, one of the first things is to change all CR types to r n, and to add a blank line at the end of the file.
                  Message 8 of 17 , Jan 17, 2012
                    I thought of that later. In my own clip library, one of the first things is to change all CR types to \r\n, and to add a
                    blank line at the end of the file. I've been caught by the missing last line more than once, especially when testing
                    using the dialog on snippets of text. The other thing I didn't compensate for was the occurrence of the string somewhere
                    other than at the beginning of the line. To do that, the \K would need to be preceded by a \R.

                    Regards,
                    John
                    RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/

                    From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of flo.gehrke
                    Sent: Tuesday, January 17, 2012 11:49
                    To: ntb-clips@yahoogroups.com
                    Subject: Re: [Clip] Remove a line


                    --- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com> , "John Shotsky" <jshotsky@...> wrote:
                    >
                    > This should do what you want.
                    > ^!Replace "(?s)^(\w{7}).+?\R.*\K\1.+?\R" >> "" AIRSW
                    > ^!IfError Next Else Skip_-1
                    >
                    > Sorting is not mandatory, but could be added.
                    >
                    > Regards,
                    > John

                    This doesn't remove a duplicate at the end of the list (with no trailing empty line). To achieve this, try...

                    ^!Replace "(^\w{7})\X+?\K\1\X+?(\R|\Z)" >> "" AWRS
                    ^!IfError End Else Skip_-1

                    Regards,
                    Flo



                    [Non-text portions of this message have been removed]
                  • John Shotsky
                    Correct, about not greedy. Another way to do that is with a negative class, which I use quite a bit. [^ r n]+ R No, the ^ doesn t carry through, so if there
                    Message 9 of 17 , Jan 17, 2012
                      Correct, about not greedy. Another way to do that is with a negative class, which I use quite a bit. [^\r\n]+\R

                      No, the ^ doesn't carry through, so if there was a match elsewhere in a line, it would match.

                      Regards,
                      John
                      RecipeTools Web Site: http://recipetools.gotdns.com/


                      -----Original Message-----
                      From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of Don
                      Sent: Tuesday, January 17, 2012 11:53
                      To: ntb-clips@yahoogroups.com
                      Subject: Re: [Clip] Remove a line

                      On 1/17/2012 10:00 AM, John Shotsky wrote:
                      > The (?s) means multiline search, so it will search without regard to line ends.
                      > The \w{7} means the first 7 letters and/or numbers.
                      > The parens around the above line makes it capture with a reference back to it of \1
                      > The .* means to skip through everything looking for the match.
                      > the \K means to keep everything before the \K.
                      > The \1 refers to that first capture, meaning it is a duplicate of the first 7 characters captured earlier.
                      > The rest of it captures that whole line, and the replacement keeps all before the \K and loses what follows – the
                      > duplicate line.
                      > The next line is a loop to keep repeating the replace until there are no duplicates left.
                      >
                      > Regards,
                      > John

                      \1.+?\R
                      means match the "back-referenced" first seven characters, plus whatever
                      that completes a line. The ? means not greedy I think.

                      But could that back-reference occur mid-line in this? Or is the ^
                      meaning line start somehow implicitly carried forward?


                      ------------------------------------

                      Fookes Software: http://www.fookes.com/
                      NoteTab website: http://www.notetab.com/
                      NoteTab Discussion Lists: http://www.notetab.com/groups.php

                      ***
                      Yahoo! Groups Links
                    • flo.gehrke
                      ... To avoid this, make ^ part of the subpattern that the back reference is reffering to -- as in my solution ;-) Another clip with less RegEx might be
                      Message 10 of 17 , Jan 18, 2012
                        --- In ntb-clips@yahoogroups.com, "John Shotsky" <jshotsky@...> wrote:
                        >
                        > No, the ^ doesn't carry through, so if there was a match elsewhere in a line, it would match.
                        >
                        > Regards,
                        > John

                        To avoid this, make '^' part of the subpattern that the back reference is reffering to -- as in my solution ;-)

                        Another clip with less RegEx might be easier to understand and is quite fast as well:

                        ^!SetScreenUpdate Off
                        ^!Set %Nr%=0
                        :Loop
                        ^!Inc %Nr%
                        ^!If ^%Nr% > ^$GetTextLineCount$ End
                        ^!Jump ^%Nr%
                        ^!Set %Left%=^$StrCopyLeft(^$GetLine$;7)$
                        ^!Replace "\R^%Left%.+" >> "" ARS
                        ^!Goto Loop

                        Regards,
                        Flo
                      • flo.gehrke
                        ... John, In my understanding, all three clips which you and humble me have posted so far have the specific advantage that duplicates are removed without
                        Message 11 of 17 , Jan 19, 2012
                          --- In ntb-clips@yahoogroups.com, "John Shotsky" <jshotsky@...> wrote:
                          >
                          > This should do what you want.
                          > ^!Replace "(?s)^(\w{7}).+?\R.*\K\1.+?\R" >> "" AIRSW
                          > ^!IfError Next Else Skip_-1
                          >
                          > Sorting is not mandatory, but could be added.

                          John,

                          In my understanding, all three clips which you and humble me have posted so far have the specific advantage that duplicates are removed without changing the order of the lines, that is: they are designed NOT to sort the whole list.

                          If we were allowed to SORT the list -- which, unfortunately, bozlawless didn't make clear -- we could have spared ourselves all those "skips, loops & jumps" by writing...

                          ^!Toolbar Sort Ascending
                          ^!Replace "(^.{7})\X+?\K(\1\X+?(\R|\Z))+" >> "" WARS

                          (providing that 'Options|Tools|Sort Removes Duplicates' is checked).

                          Regards,
                          Flo
                        • C
                          FGriends, This is a fanny situation. I used NTP 5.4/fv, for several years. One of my clips, use this code (for years, ok): ^!Open e: new index.html and he
                          Message 12 of 17 , Mar 1, 2012
                            FGriends,

                            This is a fanny situation.

                            I used NTP 5.4/fv, for several years.

                            One of my clips, use this code (for years, ok):

                            ^!Open e:\new\index.html

                            and he opened.

                            Suddenly, I receive a message like that: "Cannot open... used by other processor", concerning the same e:\new\index.html.

                            Naturally, I tried all things: the e: disk have 6 Gb free to be used, this fle index.html really exist, and I cleared all attributes of this file (with a FT command), abnd this directoru \new\ is shared. Also, "visually" I dio not have any other processors using this same file.

                            And more fanny, if I use the NTP menu MANUALLY I opened this file, but not using the ^!Open e:\new\index.html code inside a clip.

                            Additionally, I changed this clip/datas to other disk directory (m:\new\index.html) and have the same negative result.

                            There exist any possibility that this is a NTP error, or an error in his cinfiguration, etc.

                            But manually using the menu this file open, but why not using a Open in a clip?

                            Thanks,
                            Carlos.
                          • Axel Berger
                            ... I take it the problem concerns just this one file and no others? If so contains info about recently opened files. It might help to delete
                            Message 13 of 17 , Mar 1, 2012
                              C wrote:
                              > ^!Open e:\new\index.html

                              I take it the problem concerns just this one file and no others?
                              If so <NotePro.fpr> contains info about recently opened files. It might
                              help to delete that to make NoteTab forget whatever misinformation it
                              might hold.

                              You could also rename <NotePro.ini> and if that should help (I doubt it)
                              try to find the offending entry in there. Deleting that file would
                              destroy a lot of valuable stuff.

                              Axel
                            • Eb
                              As Axel has already pointed out, renaming NoteTab.ini is better than deleting it. Even better is moving it elswhere, since NoteTab replaces the file, and to
                              Message 14 of 17 , Mar 1, 2012
                                As Axel has already pointed out, renaming NoteTab.ini is better than deleting it.

                                Even better is moving it elswhere, since NoteTab replaces the file, and to restore it to its prior state, moving the original back to the NoteTab folder will automatically overwrite the replacement (subect top an "are you sure" prompt).


                                As to the original problem, one thing that has cause similar symptoms for me in the past has been an orphan NoteTab process, left behind because it did not close properly.

                                To check for this, open the Windows Taskmanager (rightclick on an empty area of the taskbar), sort the processes by name, and see if you have too many NoteTab/NotePro processes running. Two is too many if NoteTab is running, One is too many if NoteTab is NOT running. If you got more than you need, first shut down all instances of NoteTab by closing them normally, then come back to the taskmanager, select any remaining NoteTab/NotePro process, and click the "End Process" button, answer yes to "are you sure?".


                                Cheers,


                                Eb

                                --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:

                                > ...

                                > You could also rename <NotePro.ini> and if that should help (I doubt it)
                                > try to find the offending entry in there. Deleting that file would
                                > destroy a lot of valuable stuff.
                              • John Wallace
                                Most times I have something like that is when the file is being used by another program, like windows explorer, Excel, maybe IE? With windows explorer it may
                                Message 15 of 17 , Mar 1, 2012
                                  Most times I have something like that is when the file is being 'used' by another program, like windows explorer, Excel, maybe IE?
                                  With windows explorer it may be reading the E directory.
                                  Make sure you're not running some other program.

                                  John


                                  _____

                                  From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of C
                                  Sent: Thursday, March 01, 2012 10:46 AM
                                  To: ntb-clips@yahoogroups.com
                                  Subject: [Clip] Do not "open" a file




                                  FGriends,

                                  This is a fanny situation.

                                  I used NTP 5.4/fv, for several years.

                                  One of my clips, use this code (for years, ok):

                                  ^!Open e:\new\index.html

                                  and he opened.

                                  Suddenly, I receive a message like that: "Cannot open... used by other processor", concerning the same e:\new\index.html.

                                  Naturally, I tried all things: the e: disk have 6 Gb free to be used, this fle index.html really exist, and I cleared all attributes
                                  of this file (with a FT command), abnd this directoru \new\ is shared. Also, "visually" I dio not have any other processors using
                                  this same file.

                                  And more fanny, if I use the NTP menu MANUALLY I opened this file, but not using the ^!Open e:\new\index.html code inside a clip.

                                  Additionally, I changed this clip/datas to other disk directory (m:\new\index.html) and have the same negative result.

                                  There exist any possibility that this is a NTP error, or an error in his cinfiguration, etc.

                                  But manually using the menu this file open, but why not using a Open in a clip?

                                  Thanks,
                                  Carlos.






                                  [Non-text portions of this message have been removed]
                                • Axel Berger
                                  ... Yes, you re right. I use the Totalcommander for all these things and whenever I try to rename a file (back) to an already existing one, I m asked do you
                                  Message 16 of 17 , Mar 1, 2012
                                    Eb wrote:
                                    > moving the original back to the NoteTab folder will automatically
                                    > overwrite the replacement (subect top an "are you sure" prompt).

                                    Yes, you're right. I use the Totalcommander for all these things and
                                    whenever I try to rename a file (back) to an already existing one, I'm
                                    asked "do you really want to overwrite ...". So I find it most ovious to
                                    have the *.inx right next to the *.ini.

                                    Axel
                                  Your message has been successfully submitted and would be delivered to recipients shortly.