Replace line after line, is this somehow possible ?

Replace line after line, is this somehow possible ?

33
Basic UserBasic User
33

    Aug 20, 2008#1

    Hi,

    I just like to know, could I do this some way with UltraEdit ?

    Say, I have 2 textfiles open :

    1st textfile is the one that needs to be changed.
    2nd textfile is the one that contains the lines that need to replace lines in the 1st textfile.

    File 2 contains 18 lines which needs special insertion into textfile 1.

    I would like to get this done :

    Search for a specific line in file1, and automatically replace each found line with the next line from file 2.

    So, textfile 2 contains these lines :

    Code: Select all

    First line to insert.
    Second line to insert.
    Third line to insert.
    Fourth line to insert.
    Fifth line to insert.
    etc....
    
    So I need some special find an replace function that replaces each found matching line with the next line from file 2.

    So, search textfile 1 for replaceme.

    Running some kind of script or function,
    - the first occurence of replaceme is replace by First line to insert.

    - the second occurence of replaceme is replace by Second line to insert.

    - the third occurence of replaceme is replace by Third line to insert.

    - the forth occurence of replaceme is replace by Forth line to insert.

    - the fifth occurence of replaceme is replace by Fifth line to insert.



    Is this, some way, possible please ?

    6,687587
    Grand MasterGrand Master
    6,687587

      Aug 21, 2008#2

      Yes, with a macro. I have written such macros so often in the past that I could write this one in 5 minutes. It is important for the macro that only the 2 files are open and that the second file with the lines to insert has the focus when starting the macro. You hopefully don't have any line in your second file which starts with character # because that would result in a not working macro and you would need a different non regular expression special character which surely does not exist at start of any line in your second file with the lines to insert.

      The macro property Continue if a Find with Replace not found or Continue if search string not found must be checked for this macro.

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      SelectAll
      Clipboard 9
      Copy
      NextWindow
      Top
      Paste
      ClearClipboard
      Clipboard 0
      IfColNumGt 1
      "
      #
      "
      Else
      "#
      "
      EndIf
      Top
      Loop
      IfCharIs "#"
      ExitLoop
      EndIf
      StartSelect
      Key END
      Find "replaceme"
      Replace "^s"
      IfFound
      EndSelect
      Top
      DeleteLine
      Else
      ExitLoop
      EndIf
      EndLoop
      Top
      Find RegExp Select "%#^r++^n"
      Delete

      Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.
      Best regards from an UC/UE/UES for Windows user from Austria

      33
      Basic UserBasic User
      33

        Aug 21, 2008#3

        Thank you very much Mofi, it works perfect ! :D :D