5

I have an extremely long text file (about 15k lines). It only contains numbers (6 numbers separated by a space). I am only interested in the first three numbers of each line. I have tried the column mode selection and drag it down, however it's very slow, and I have several files to handle.

I have also tried the Begin/End Selection trick, however it doesn't seem to work with columns.

Is there a way to automatically select only the three last columns of numbers in a text file ? One way it could would be an option to select all lines in specified column(s). Is it possible whatsoever ?

7
  • Have you looked into RegEx? I don't use N++, but Scintilla Text Editor, which I do use, allows for finds and highlights based on Regular Expression, which should make easy work of this. Another option could be Excel which should allow you to capture only the first 3 digits of each line and move them to another line. Mar 22, 2017 at 21:20
  • How would Regular expression tool help ? There are a lot of tools for searching in Notepad but I cannot figure how they would be useful for that case. As for Excel, I'll give it a try. Mar 23, 2017 at 9:21
  • Regular expression is a language, not a tool. I have found it helpful from time to time for assisting in more complex search and replace where I'm trying to match target strings that are more complex. Notepad++ does support it: docs.notepad-plus-plus.org/index.php/Regular_Expressions Mar 23, 2017 at 16:17
  • 1
    There are also a handful of questions on SE about this exact process: stackoverflow.com/questions/5516119/… Mar 23, 2017 at 16:19

2 Answers 2

15

Try this:

  1. Press CTRL+Home to move the typing cursor to the top of the document.
  2. Now, use the scroll bar to rapidly scroll to the bottom of the document without changing the position of the typing cursor. You can drag the slider portion of the scroll bar to rapidly reach the bottom of the document. It is really fast.
  3. Move your mouse pointer after the third number of the last line, hold down Alt+Shift and click.

Bingo!

0
3

This can be done with the following regular expression, assuming your numbers are numbers only (ie. no commas, decimal points):

1111 2222 3333 4444 5555 6666
1111 2222 3333 4444 5555 6666
1111 2222 3333 4444 5555 6666
1111 2222 3333 4444 5555 6666
1111 2222 3333 4444 5555 6666
1111 2222 3333 4444 5555 6666
1111 2222 3333 4444 5555 6666
1111 2222 3333 4444 5555 6666

CTRL-H to go to Find and Replace

Find what: .*\s(\d+\s\d+\s\d+)$
Replace with: \1
Search Mode: Regular expression

An explanation of the find regex:

.*  = match anything, repeating
\s  = match single whitespace
(   = start capture group
\d+ = match one or more numerals
\s  = match single whitespace
\d+ = match one or more numerals
\s  = match single whitespace
\d+ = match one or more numerals
)   = end capture group
$   = match end of line

And the replace box:

\1 = capture group 1 from the prior regex match (everything matched between the ( and the ))

This took a few seconds to replace and leaves you with the last three columns of numbers, ie.

4444 5555 6666
4444 5555 6666
4444 5555 6666
4444 5555 6666
4444 5555 6666
4444 5555 6666
4444 5555 6666
4444 5555 6666
4444 5555 6666
4444 5555 6666
4444 5555 6666

Screenshot of NPP replace box:

notepad++ find and replace regex

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .