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

Re: [NTB] Executing a series of commands

Expand Messages
  • Don Daugherty
    ... Alex, Is string1 always followed immediately by 5 contigous spaces, or are the spaces anywhere, contigous or not after string1? In the first case you
    Message 1 of 11 , Jan 11, 2005
    • 0 Attachment
      > I would like to automate this series of commands:
      > find a string1, replace it by a string2, and then replace the next five
      > spaces by tabs,
      > and repeat this sequence for every occurrence of string1.
      > (Assume the next occurrence of string1 is beyond the 5th space.)
      > How do I do this?
      > Is this possible with the free version, or do I need another version?
      >

      Alex,
      Is string1 always followed immediately by 5 contigous spaces, or are the
      spaces "anywhere, contigous or not" after string1?

      In the first case you could use
      ^!Replace "String1 " >> "String2^T^T^T^T^T" WAS
      ;^T is the code for tab"

      In the second case you would need a more step-by-step approach:

      :Loop1
      ^!Replace "String1" >>"String2" S
      ^!IfError End
      ^!Set %N%=0
      :Loop2
      ^!Inc %N%
      ^!Replace " " >> "^T" S
      ^!IfError End
      ^!If ^%N%<5 Loop2 Else Loop1
    • Don Daugherty
      My reply (sent 30 seconds ago) involved clips. If that s what you wanted, reply on the clips list if further discussion is needed. If you are not a clipper
      Message 2 of 11 , Jan 11, 2005
      • 0 Attachment
        My reply (sent 30 seconds ago) involved clips. If that's what you wanted,
        reply on the clips list if further discussion is needed. If you are not a
        "clipper" and were looking for a manual approach, reply here if the clip
        syntax doesn't answer your question. (I shouldn't have given a clip
        solution in this forum. I forgot which one I was in.) (Sorry, Jody)
      • Alex Plantema
        ... Thanks for your solution! The spaces are not contiguous, so I need the second version. I want to automate these replacements. I don t know if I need clips
        Message 3 of 11 , Jan 12, 2005
        • 0 Attachment
          Op woensdag 12 januari 2005 00:22 schreef Don Daugherty:

          > My reply (sent 30 seconds ago) involved clips. If that's what you
          > wanted, reply on the clips list if further discussion is needed. If
          > you are not a "clipper" and were looking for a manual approach, reply
          > here if the clip syntax doesn't answer your question. (I shouldn't
          > have given a clip solution in this forum. I forgot which one I was
          > in.) (Sorry, Jody)

          Thanks for your solution! The spaces are not contiguous, so I need the second version.
          I want to automate these replacements.
          I don't know if I need clips or something else.
          Does the free version have clips or do I need another version?
          Where should I enter the clip you wrote?

          Alex.
        • Alec Burgess
          Alex: The non-clip solution to what I *think* you are after. To replace apple by pear and also replace the next not neccessarily immediately following five
          Message 4 of 11 , Jan 12, 2005
          • 0 Attachment
            Alex:

            The non-clip solution to what I *think* you are after.
            To replace apple by pear and also replace the next not neccessarily
            immediately following five spaces by tabs (I hope that's what you meant by
            "not contiguous"). This uses regular expressions (regex). Look for regular
            expressions in the Help for some more detail.

            In the Replace box:
            Find=apple{.*}\s\s\s\s\s
            Replace=pear\1\t\t\t\t\t

            and check the "Use regular expressions box"

            Note: this would replace the *last* five spaces not the first five spaces.

            If what you need is:
            apple car truck boat girl boy ==>
            appleTABcarTABtruckTABboatTABgirlTABboy
            as I suspect then this should work

            Find={apple}{.*}{\s{.*}\s{.*}\s{.*}\s{.*}\s}
            Replace=pear\1\t\2\t\3\t\4\t\5\t

            Note: Again, if there are more than 5 following space separated words on a
            line, the *last* five spaces would be converted to tabs.

            Regards ... Alec
            --
            ( ) { } [ ] \ | 9 0 + = () {} []


            ---- Original Message ----
            From: "Alex Plantema" <alex.plantema@...>
            To: <notetab@yahoogroups.com>
            Sent: Wednesday, January 12, 2005 04:50
            Subject: [gla: Re: [NTB] Executing a series of commands

            > Op woensdag 12 januari 2005 00:22 schreef Don Daugherty:
            >
            >> My reply (sent 30 seconds ago) involved clips. If
            >> that's what you wanted, reply on the clips list if
            >> further discussion is needed. If you are not a
            >> "clipper" and were looking for a manual approach, reply
            >> here if the clip syntax doesn't answer your question.
            >> (I shouldn't have given a clip solution in this forum.
            >> I forgot which one I was in.) (Sorry, Jody)
            >
            > Thanks for your solution! The spaces are not contiguous,
            > so I need the second version. I want to automate these
            > replacements.
            > I don't know if I need clips or something else.
            > Does the free version have clips or do I need another
            > version?
            > Where should I enter the clip you wrote?
          • Don - htmlfixit.com
            ... all versions support clips they are very easy to use for detailed help on them join the clips list you just copy the clip and then in your notetab program
            Message 5 of 11 , Jan 12, 2005
            • 0 Attachment
              Alex Plantema wrote:
              > Op woensdag 12 januari 2005 00:22 schreef Don Daugherty:
              >
              >
              >>My reply (sent 30 seconds ago) involved clips. If that's what you
              >>wanted, reply on the clips list if further discussion is needed. If
              >>you are not a "clipper" and were looking for a manual approach, reply
              >>here if the clip syntax doesn't answer your question. (I shouldn't
              >>have given a clip solution in this forum. I forgot which one I was
              >>in.) (Sorry, Jody)
              >
              >
              > Thanks for your solution! The spaces are not contiguous, so I need the second version.
              > I want to automate these replacements.
              > I don't know if I need clips or something else.
              > Does the free version have clips or do I need another version?
              > Where should I enter the clip you wrote?
              >
              > Alex.
              all versions support clips
              they are very easy to use
              for detailed help on them join the clips list
              you just copy the clip and then in your notetab program hit f4 to open
              the clips window (if it isn't already open)
              right click in a clip library window and choose add from clipboard
              you now have the clip saved

              be careful when copying from email that no lines have wrapped
              usually every line starts with a ; or a !
              so if you have a line starting with something else it likely got wrapped
              in transmission


              Good luck. If you need more help getting clips going write privately or
              visit the clips list as they try very hard to keep clips off of this
              list that is meant for very basic questions and answers.
            • Alex Plantema
              ... Thanks a lot! This lead me to: Find=apple{.*} s{.*} s{.*} s{.*} s{.*} s Replace=pear 1 t 2 t 3 t 4 t 5 t With Replace All, this does exactly what I was
              Message 6 of 11 , Jan 12, 2005
              • 0 Attachment
                Op woensdag 12 januari 2005 15:45 schreef Alec Burgess:

                > If what you need is:
                > apple car truck boat girl boy ==>
                > appleTABcarTABtruckTABboatTABgirlTABboy
                > as I suspect then this should work
                >
                > Find={apple}{.*}{\s{.*}\s{.*}\s{.*}\s{.*}\s}
                > Replace=pear\1\t\2\t\3\t\4\t\5\t
                >
                > Note: Again, if there are more than 5 following space separated words
                > on a line, the *last* five spaces would be converted to tabs.

                Thanks a lot! This lead me to:

                Find=apple{.*}\s{.*}\s{.*}\s{.*}\s{.*}\s
                Replace=pear\1\t\2\t\3\t\4\t\5\t

                With Replace All, this does exactly what I was looking for.

                Maybe my description wasn't clear enough: there are exactly 5 spaces, each one between two words, before the end of the line.
                It works as you described: when there are 6 spaces, the first one isn't converted. For some reason ".*" is the largest possible string.

                Alex.
              • Alex Plantema
                ... I found it, and I got your version working too! Thanks for this introduction in clips. Alex.
                Message 7 of 11 , Jan 12, 2005
                • 0 Attachment
                  Op woensdag 12 januari 2005 16:59 schreef Don - htmlfixit.com:

                  > all versions support clips
                  > you just copy the clip and then in your notetab program hit f4 to open
                  > the clips window (if it isn't already open)
                  > right click in a clip library window and choose add from clipboard
                  > you now have the clip saved

                  I found it, and I got your version working too!
                  Thanks for this introduction in clips.

                  Alex.
                • Alec Burgess
                  ... Google greedy regexp or greedy regular expression for an explanation. In short, Notetab s regular expression engine (current version) is *always*
                  Message 8 of 11 , Jan 12, 2005
                  • 0 Attachment
                    Alex:

                    > It works as you described: when there are 6 spaces, the
                    > first one isn't converted. For some reason ".*" is the
                    > largest possible string.

                    Google "greedy regexp" or "greedy regular expression"
                    for an explanation.

                    In short, Notetab's regular expression engine (current version) is *always*
                    greedy. Perl and some other regular expression engines support special
                    syntax for non-greedy regular expressions. Rumor is that the next version -
                    Notetab 5 - will support non-greedy regexps.

                    At present if you need non-greedy expressions you have to use clip code -
                    basically something like:
                    loop
                    find
                    replace
                    goto loop

                    clips can be discussed on the NTB-clip list:
                    http://groups.yahoo.com/group/ntb-clips


                    Regards ... Alec
                    --
                    ( ) { } [ ] \ | 9 0 + = () {} []


                    ---- Original Message ----
                    From: "Alex Plantema" <alex.plantema@...>
                    To: <notetab@yahoogroups.com>
                    Sent: Wednesday, January 12, 2005 11:35
                    Subject: [gla: Re: [NTB] Executing a series of commands

                    > Op woensdag 12 januari 2005 15:45 schreef Alec Burgess:
                    >
                    >> If what you need is:
                    >> apple car truck boat girl boy ==>
                    >> appleTABcarTABtruckTABboatTABgirlTABboy
                    >> as I suspect then this should work
                    >>
                    >> Find={apple}{.*}{\s{.*}\s{.*}\s{.*}\s{.*}\s}
                    >> Replace=pear\1\t\2\t\3\t\4\t\5\t
                    >>
                    >> Note: Again, if there are more than 5 following space
                    >> separated words on a line, the *last* five spaces would
                    >> be converted to tabs.
                    >
                    > Thanks a lot! This lead me to:
                    >
                    > Find=apple{.*}\s{.*}\s{.*}\s{.*}\s{.*}\s
                    > Replace=pear\1\t\2\t\3\t\4\t\5\t
                    >
                    > With Replace All, this does exactly what I was looking
                    > for.
                    >
                    > Maybe my description wasn't clear enough: there are
                    > exactly 5 spaces, each one between two words, before the
                    > end of the line.
                    > It works as you described: when there are 6 spaces, the
                    > first one isn't converted. For some reason ".*" is the
                    > largest possible string.
                  • Wayne VanWeerthuizen
                    ... Instead try: Find=apple{ s*} s{ s*} s{ s*} s{ s*} s{ s*} s It is generally recommended to avoid using .* in regular expressions. Rather one should be
                    Message 9 of 11 , Jan 12, 2005
                    • 0 Attachment
                      Alex Plantema wrote:
                      > Find=apple{.*}\s{.*}\s{.*}\s{.*}\s{.*}\s
                      > Replace=pear\1\t\2\t\3\t\4\t\5\t
                      >
                      > With Replace All, this does exactly what I was looking for.
                      >
                      > Maybe my description wasn't clear enough: there are exactly
                      > 5 spaces, each one between two words, before the end of the
                      > line.
                      >
                      > It works as you described: when there are 6 spaces, the first
                      > one isn't converted. For some reason ".*" is the largest
                      > possible string.

                      Instead try:

                      Find=apple{\s*}\s{\s*}\s{\s*}\s{\s*}\s{\s*}\s

                      It is generally recommended to avoid using .* in regular
                      expressions. Rather one should be explicit regarding
                      what characters are to be matched, especially when using
                      * or +.


                      Wayne VanWeerthuizen
                    • Alex Plantema
                      ... Did you mean apple{ B*} s{ B*} s{ B*} s{ B*} s{ B*} s ? You re right, in a lot of cases it may be better to search for non-spaces between the spaces. This
                      Message 10 of 11 , Jan 12, 2005
                      • 0 Attachment
                        Op donderdag 13 januari 2005 00:26 schreef Wayne VanWeerthuizen:

                        > Alex Plantema wrote:
                        >> Find=apple{.*}\s{.*}\s{.*}\s{.*}\s{.*}\s
                        >> Replace=pear\1\t\2\t\3\t\4\t\5\t

                        > Instead try:
                        >
                        > Find=apple{\s*}\s{\s*}\s{\s*}\s{\s*}\s{\s*}\s
                        >
                        > It is generally recommended to avoid using .* in regular
                        > expressions. Rather one should be explicit regarding
                        > what characters are to be matched, especially when using
                        > * or +.

                        Did you mean apple{\B*}\s{\B*}\s{\B*}\s{\B*}\s{\B*}\s ?
                        You're right, in a lot of cases it may be better to search for non-spaces between the spaces.
                        This matches the first 5 spaces instead of the last 5 spaces on the line.

                        Alex.
                      • Wayne VanWeerthuizen
                        ... Oops. That what I get for hurrying to fast. I meant to write: apple{[^ s]*} s{[^ s]*} s{[^ s]*} s{[^ s]*} s{[^ s]*} s Your B version might as good or
                        Message 11 of 11 , Jan 12, 2005
                        • 0 Attachment
                          Alex Plantema wrote to me:
                          > Did you mean apple{\B*}\s{\B*}\s{\B*}\s{\B*}\s{\B*}\s ?

                          Oops. That what I get for hurrying to fast. I meant to write:

                          apple{[^\s]*}\s{[^\s]*}\s{[^\s]*}\s{[^\s]*}\s{[^\s]*}\s

                          Your \B version might as good or even better, depending on the
                          situation in which it is used.

                          > You're right, in a lot of cases it may be better to search
                          > for non-spaces between the spaces. This matches the first
                          > 5 spaces instead of the last 5 spaces on the line.

                          Yes. That is the primary point of not using .*

                          Also note: the nonspace versions execute faster than the .*
                          version, since the regular expression engine doesn't have to
                          "backtrack". With the .* version, the regular expression
                          engine attempts to have the first .* match everything to the
                          end of the line (it is greedy). But then it has to revise
                          that decision, in order for the second .* to have something
                          to match. Then it has to revise both of those shorter still,
                          so that the third .* can match. By the time it has matched
                          the fifth .*, the regular expression engine has wasted a
                          significant amount of processor time on extraneous
                          calculations.

                          On the other hand the nonspace versions (/B* or [^\s]*) are
                          direct and to the point, so the search is performed in
                          a much more direct and thus efficient manner.

                          That is the other major reason why experts frown upon
                          the use of .*

                          And the more .* are combined in the same expression, the
                          less efficient the search gets. It is even possible to
                          write a regular expression so horrible, that the search
                          would take over a _century_, even with a fast computer
                          and a small document.
                        Your message has been successfully submitted and would be delivered to recipients shortly.