Delete or copy to a new file a group of lines

Delete or copy to a new file a group of lines


    Jan 06, 2012#1

    I have searched the forum and cannot seem to find an answer to this question. I have an ultraedit file that contains 50 columns with a column header and data in each column. The file is 12,274,267 rows. Because of the size it takes so much RAM to import this into my SQL Server. I want to only take the top 1000 rows and delete all the rest. I am doing this because we are trying to test using the BCP command to import this file straight from a .csv into SQL Server. Testing the 12.2 million is just far too big. I can do a select all and then move down to 1000 but when I select delete line it only deletes the 1 line my cursor ends at. Maybe there is a quickie script to say select only top 1000 and delete the rest or select top 1000 and copy paste put in another .csv???

    Grand MasterGrand Master

      Jan 07, 2012#2

      The command Delete Line is written to delete just the line the caret is placed in without the need to select it. If you want to copy the first 1000 lines, simply select them and copy them to a new file. It is also possible to select everything from line 1001 to end of file and delete those lines, but that would take longer than simply copying the first 1000 lines into a new file.

      Manual steps to select the first 1000 lines and copy them.
      • Open the file, caret is at top of the file.
      • Press Ctrl+G to execute command Search - Goto.
      • Enter 1001.
      • Press and hold left SHIFT key to not just go to line 1001, but additionally selected everything from current position of the caret to the new position.
      • Press RETURN key or click on button Goto while still holding SHIFT key.
      • The dialog is closed, the caret is now at start of line 1001 and the first 1000 lines are selected. Press Ctrl+C to copy the selected lines to active clipboard.
      • Press Ctrl+N to create a new file.
      • Press Ctrl+V to paste the copied lines into this file.
      • Press F12 (or Ctrl+S) to save the new file with the first 1000 lines with a name you have to enter
      Those few steps executed manually in 5 seconds (if knowing all the hotkeys) as UltraEdit macro (with some additional commands):

      IfExtIs "CSV"

      GotoLineSelect 1001 1
      Clipboard 9

      Clipboard 0

      SaveAs ""

      The same as script (without using a clipboard because of using a string variable):

      Code: Select all

      if (UltraEdit.document.length > 0) {
         if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
         else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();;
         var sBlock = UltraEdit.activeDocument.selection;
      Manual steps for deleting all lines below the first 1000 lines:
      • Open the file, caret is at top of the file.
      • Press Ctrl+G to execute command Search - Goto.
      • Enter 1001.
      • Press RETURN key or click on button Goto.
      • Press Ctrl+Shift+End to move caret to end of file and additionally select everything from start of line 1001.
      • Press key DEL to delete the selected block.
      • Save the modified file with Ctrl+S