Menu

Macro with search to end of file

2008-06-04
2012-11-13
  • Mike Hedman

    Mike Hedman - 2008-06-04

    Hi,

    I've recorded a macro which repeats a previous search, and performs a small action.  So the keystrokes of the macro are:
    F3
    <end>
    Hello

    The intention is to add the word "Hello" to the end of each line which has the searched for text.  But when I run the macro using the "Run a macro multiple times" and select "run until end of file", N++ hangs.

    I have a feeling that the search again (F3) loops back to the top of the file, and so the macro player never thinks that it gets to the end of the file.

    Is there anything I can do to prevent this?  Or is it just a bug?

    Thanks,
    Mike

     
    • Fool4UAnyway

      Fool4UAnyway - 2008-06-04

      I suggest you can easily check what repeating the macro does by either execute it a number of times manually, or entering a number (say 3) in the Run Macro Multiple Times dialog. Perhaps you will find that the dialog will find the same match over and over again.

      You can also use either Find/Replace dialog to add a word to each line containing your search string.

      Select or check the regular expression mode.

      In the Find field, you'll want to search for your word preceded or followed by any number of characters, including none at all:

      (^.*wordtosearchfor.*$)

      ^_______ = match must be/start at the beginning of the line (not necessary with .*)
      ._______ = search for any character
      *_______ = search for any number of the precedinng character (0 or more times)
      (......) = groups an expression to allow re-placing it in the Replace field
      $_______ = match must be/end at the end of the line (not necessary with .*)

      In the Replace field, you will simply re-place the found match and add the word Hello:

      \1Hello

      \1______ = refers to the first () grouped expression in the Find field and re-places it

      See also:

      "how to append lines with a comma or other character" (Help forum)
      http://sourceforge.net/forum/forum.php?thread_id=1967758&forum_id=331754

       
      • Fool4UAnyway

        Fool4UAnyway - 2008-06-04

        Find field:
        ^(.*wordtosearchfor.*)$

        I suggest you use the advanced Find/Replace dialog (CTRL+R), because the CTRL+H Replace dialog will (also) find (and replace) the same match over and over again...