Tapatalk

Need macro to select and cut odd lines

Need macro to select and cut odd lines

2
NewbieNewbie
2

    Oct 10, 2007#1

    Greetings all,

    I am currently working on a massive bioinformatics database and need to select only odd lines in a file and then cut them. An example of my data is as follows:

    Code: Select all

          S  K  L  M  A  I  S  K  P  R  N  L  S  L  R  E  Q  R  E  V  
    601   agcaagttgatggctatctcaaaacctcgaaacctgtctctacgtgaacaaagagaggtt  660
          L  R  A  D  M  S  W  Q  Q  E  T  N  P  V  V  E  T  H  D  S  
    661   ctgagagcagatatgtcttggcagcaggaaaccaaccccgtcgtggagacacatgactct  720
          E  A  S  R  Q  K  F  R  H  F  Q  Y  L  K  V  S  G  P  H  E  
    721   gaggcatctcgtcaaaagttcagacatttccagtatttgaaagtgtctgggccccatgaa  780
          A  L  S  Q  L  W  E  L  C  L  Q  W  L  R  P  E  I  H  T  K  
    781   gccctgagccaactctgggagctctgtcttcaatggctgagaccagagattcatacaaag  840
    
    Is there a way to do this with UE 13.10a+1?

    Thank you!

    5
    NewbieNewbie
    5

      Oct 10, 2007#2

      Try this


      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Bottom
      " --- This we are doing if the even line is the last line and there
      " --- is not next line char, so to avoid the deletion of even line
      Top --- we are putting new line char. at the end of the file.
      Loop
      DeleteLine
      Key DOWN ARROW
      IfEof
      ExitMacro
      EndIf
      EndLoop

      6,685587
      Grand MasterGrand Master
      6,685587

        Oct 10, 2007#3

        InsertMode
        ColumnModeOff
        HexOff
        ClearClipboard
        Bottom
        IfColNum 1
        Else
        "
        "
        EndIf
        Top
        Loop
        IfEof
        ExitLoop
        EndIf
        SelectLine
        CutAppend
        Key DOWN ARROW
        EndLoop

        Or much faster which simply deletes line 1, 3, 5, ...

        InsertMode
        ColumnModeOff
        HexOff
        UnixReOff
        Bottom
        IfColNum 1
        Else
        "
        "
        EndIf
        Top
        Find MatchCase RegExp "%[ ^t]+[A-Z] *^p"
        Replace All ""
        Best regards from an UC/UE/UES for Windows user from Austria

        2
        NewbieNewbie
        2

          Oct 10, 2007#4

          Hey guys,

          Thanks for the responses! I am a biologist by trade and have little experience in script writing. I copied the scripts you guys posted but when I went to run them nothing happened... I am sure it's something on my end...

          6,685587
          Grand MasterGrand Master
          6,685587

            Oct 11, 2007#5

            If you only want to delete the odd lines and not cut them all into the clipboard you don't really need a macro. Just make sure the last line of the file has a line termination.

            Press Ctrl+End to move the cursor to end of the file. If the cursor is now not at column 1, press key Return.
            Press Ctrl+Home to move the cursor back to top of the file.
            Press Ctrl+R to open the replace dialog.
            Enter %[ ^t]+[A-Z] *^p in the Find What field.
            Make sure nothing is in the Replace With field.
            Check the options Match Case and Regular Expressions and uncheck all other. Make sure Current File is selected in Replace Where group.
            Press the button Replace All.

            If that does not work, you maybe have a UNIX or MAC file openend without conversion to DOS (see second cell on status bar at top of the UltraEdit window) and therefore ^p does not find a CRLF. Use ^n for UNIX or ^r for MAC instead in the regular expression search string.
            Or you have actually not the UltraEdit regular expression engine selected in the search configuration dialog - see topic Readme for the Find/Replace/Regular Expressions forum.


            If you want the cutted lines collected in the current clipboard, do following:

            Click on Macro - Record Macro.
            Enter a name for the macro, uncheck the first property for the Cancel dialog, but check the second property for the Continuing macro execution when a search string is not found.
            Start the recording with clicking on button OK.
            Stop the recording with clicking on Macro - Stop Recording.
            Click on Macro - Edit Macro to open the just recorded macro.
            Go to your browser and copy the lines of one of the macros to the Windows clipboard.
            Back to UltraEdit select the first 3 lines in the edit macro dialog and press Ctrl+V to replace it with the macro code. The 4th line which is the command to select the regular expression engine you currently use is now at bottom of the macro.
            Press the button Close and confirm modification of the macro with Yes.
            Click on Macro - Play Again to run the macro now.


            If whether the replace command nor the macro works, the file is opened in read-only mode indicated by R/O in the status bar of UltraEdit.
            Best regards from an UC/UE/UES for Windows user from Austria