简体   繁体   中英

Deleting all the lines before a WORD on sublime text

I have a Big Text File that contains +1M Lines

and there's a word johnd on line 45280525. I want to delete all the lines before it.

How I can do that using Sublime Text?

Note that Notepad++ won't work with this file.

You can go to the line using menu > Goto > Goto Line...

or press Ctrl + G .

You might be looking for the Mark feature:

  • Ctrl + G to go to the last line you want to select, by number.
  • Edit > Mark > Set Mark to set your selection-end marker.
  • Ctrl + G (or Ctrl + Home ) to go to the first line you want to select.
  • Edit > Mark > Delete to Mark

Otherwise, you can write a code for open file as text ... delete the rows you need, save and ... close.

A bit of a hack, and it only works if there is at least one type of brackets that are not used in the text.

  1. Crate an opening bracket at the beginning of the file ( ( , [ or { ).
  2. Ctrl+F, search for your word (" johnd ")
  3. Create a closing bracket before the word, corresponding to the opening bracket ( ) , ] or } )
  4. Shift+Ctrl+M, jump to opposite bracket (Ctrl+M) while selecting text (Shift).
  5. Delete selected text and the brackets.

There's probably a better way to do this, but it's the solution I could think of.

If your file turns out to be too big to edit in Sublime Text, at a Linux command line you could do:

sed -ne '/johnd/,$p' myfile.txt > edited.txt
mv edited.txt myfile.txt

That prints all of the lines from the one matching johnd to the end of the file. The output is captured to a new file and then renamed back to replace the original file.

  1. Place your cursor at the start of the first line you want to keep (eg with Ctrl + F )
  2. Ctrl + Shift + Home to select all text up to the beginning of the file
  3. ⌫ Delete

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM