Delete lines from a separate files

Delete lines from a separate files

2
NewbieNewbie
2

    Dec 19, 2005#1

    Hello,

    I have to cleand up many files. Is it possible by using a macro to doing something like that?
    I only want to delete lines in File 2, who have an entry in File1.
    For Example:

    File1: 400 entries
    2104677 --- this customer should be deleted in File2
    2184943
    1391879
    2351252
    4248990
    1408022
    1409449
    5120910
    5154349

    File2: 1600 entries
    2100149," Text"Text"
    2103401," Text"Text"
    2104677," Text"Text" --- same customernumber from File1 this line should be deleted
    2107837," Text"Text"
    2107944," Text"Text"
    2108751," Text"Text"
    2110054," Text"Text"
    2111580," Text"Text"
    2111870," Text"Text"
    2113397," Text"Text"
    2114312," Text"Text"

    Thanks for all answers.

    Best wishes,

    Andreas Harde

    344
    MasterMaster
    344

      Dec 20, 2005#2

      Hi Andreas, tag Mofi

      I just thougt "make him a pleasure" and do the macro for him, but I'm stuck :cry:
      I'm sure its only a small damn error, but I don't find it.

      Take this macro:
      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Top
      Loop
      PlayMacro 1 "KEY_HOME"
      SelectWord
      Copy
      NextDocument
      Top
      Loop
      Find "^c"
      IfFound
      DeleteLine
      Else
      ExitLoop
      EndIf
      EndLoop

      PreviousDocument
      Key DOWN ARROW
      IfEof
      ExitLoop
      EndIf
      EndLoop
      where key-home is:

      Code: Select all

      Key HOME
      IfColNumGt 1
      Key HOME
      EndIf
      and take 2 files(say tab A and B):

      A:

      Code: Select all

      xxx
      yyy
      zzz
      B:

      Code: Select all

      xxx lalala
      yyy blabla
      zzz f...
      Point cursor to file A and run the makro.
      Only the FIRST Word in File A is replaced in file B. i rearranged lines so I can say this for sure.
      Also, still "xxx" is in the clipboard, but I expect it to be zzz.

      But "looping" is ok, replace red code with "paste" and see.

      Any ideas ?
      Normally using all newest english version incl. each hotfix. Win 10 64 bit

      6,686585
      Grand MasterGrand Master
      6,686585

        Dec 20, 2005#3

        Nesting loops is not possible in macro language of UltraEdit. The inner loop must be written into a separate macro, which is called in the loop of the main macro.

        I took my code posted at Delete lines that are present in another file? and made the green modifications for Andreas. This macro will not work if the search strings contain UltraEdit style regular expression characters like +^*... But it should work for Andreas according to his example. Andreas, make sure that the file to modify also ends with a blank line (last line has a CRLF == ^p).

        With my improved macro experiences since May 2005 I would do this macro better with using an UltraEdit clipboard instead of Windows clipboard and without switching between the 2 documents for each search and replace to improve speed of macro dramatically, but I'm too lazy to develop it now. Christmas is coming!

        InsertMode
        ColumnModeOff
        HexOff
        UnixReOff
        NextWindow
        Top
        PreviousWindow
        Bottom
        IfColNum 1
        Else
        "
        "
        EndIf
        Top
        Loop
        Find "^p^p"
        IfFound
        "
        "
        Top
        Else
        ExitLoop
        EndIf
        EndLoop
        Top
        Loop
        StartSelect
        Key END

        Copy
        EndSelect
        Key HOME
        Key HOME
        Key DOWN ARROW

        NextWindow
        Find RegExp "%^c*^p"
        Replace All ""
        PreviousWindow
        IfEof
        ExitLoop
        EndIf
        EndLoop
        UnixReOn

        Remove the last red command, if you use regular expression in UltraEdit style by default instead of Unix style.
        For UltraEdit v11.10c and lower see Advanced - Configuration - Find - Unix style Regular Expressions.
        For UltraEdit v11.20 and higher see Advanced - Configuration - Searching - Unix style Regular Expressions.
        Macro commands UnixReOn/UnixReOff modifies this setting.
        Best regards from an UC/UE/UES for Windows user from Austria

        344
        MasterMaster
        344

          Dec 20, 2005#4

          Thanx Mofi,

          So here is the solution with 1 logical macro only, putting this all together :D
          The other 2 macros everybody should use by default ! :idea:

          Clipboard 9 is used not to "damage" user-default-clipboard 0.
          It is reset in setDefaults.

          Macro "delSameIn2files".
          File(tab) 1 is the file where the source is.
          File(tab) 2 is the file where lines are deleted.
          The word has to be at the beginning of the line.
          Cursor must be anywhere in File(tab) 1 !

          Code: Select all

          InsertMode
          ColumnModeOff
          HexOff
          UnixReOff
          Bottom
          IfColNum 1
          Else
          "
          "
          EndIf
          Top
          Loop 
          PlayMacro 1 "KEY_HOME"
          Clipboard 9
          SelectWord 
          Copy 
          NextDocument
          Top
          Find RegExp "%^c*^p"
          Replace All ""
          PreviousDocument
          Key DOWN ARROW
          IfEof
          ExitLoop
          EndIf
          EndLoop
          PlayMacro 1 "setDefaults"
          
          Macro "KEY_HOME" (which positions cursor to Col1 UE-setting independant)

          Code: Select all

          Key HOME
          IfColNumGt 1
          Key HOME
          EndIf
          
          Macro "setDefaults" (at the end of each macro: set to (user)-defaults)

          Code: Select all

          InsertMode
          ColumnModeOff
          HexOff
          UnixReOn
          Clipboard 0
          
          Merry Xmas

          Bego
          Normally using all newest english version incl. each hotfix. Win 10 64 bit

          2
          NewbieNewbie
          2

            Dec 22, 2005#5

            Hallo Mofi, hallo Bego,

            thanks for all the things you do to solve may problem.
            It seems to be christmas :-)
            I know, it takes time to find the right code, so thanks again.

            @Mofi:

            I have tested you macro.
            I have entered a blank line in each row, like this
            1101340," bla bla

            1104603," bla bla

            1107341," bla bla

            If i starts the macro in Tab 1 i get the following massage
            Error "Suchtext nicht gefunden"

            Whats wrong?

            @Bego

            I have tested you macro, too.
            I have copied the 3 codes into my ue by using the correct names.
            If i started the macro, i get the following message:
            "Next Document"
            It seems, UE don't understand that instruction.
            I'm using the version 10.00c

            Marry Christmas from Germany
            Andreas Harde

            344
            MasterMaster
            344

              Dec 22, 2005#6

              Hi Andreas,

              Your problem you asked Mofi for is that you need to set the property "continue searching if nothing found" to the macro.
              Menu "makro, "delete-change property".
              Choose you macro and activate the flag I described.

              2nd: If you only have 2 files open, Replace "NextDocument" with "PreviousDocument". It should then run too.
              Maybe it's a new command, I don't know.
              If it does not work, try NextWindow / PreviousWindow.


              Merry X-mas too

              Bego :D
              Normally using all newest english version incl. each hotfix. Win 10 64 bit

              6,686585
              Grand MasterGrand Master
              6,686585

                Dec 22, 2005#7

                You have to activate the macro property Continue if a Find with Replace not found for my macro or the macro execution is stopped with the error message you posted when a search string in file 1 is not found in file 2.

                "NextDocument" (without space) is only supported by UltraEdit v10.10 or higher.
                Best regards from an UC/UE/UES for Windows user from Austria