Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to get rid of everything after a column in Notepad++. Column mode is not an option. Is it possible?

What I have:

70.97.110.40    159 ms          [n/a]                   21              
70.97.117.177   134 ms          [n/a]                   21              
70.97.120.10    75 ms           [n/a]                   21              
70.97.122.105   87 ms           www.portless.net        21              
70.97.122.106   89 ms           www.popovetsky.org      21              
70.97.122.107   95 ms           www.psmythe.net         21              
70.97.122.104   98 ms           wasabi.prostructure.com 21              
70.97.122.108   89 ms           crm.prostructure.com    21              
70.97.122.109   87 ms           internal.prostructure.com21 

What I want:

70.97.110.40
70.97.117.177
70.97.120.10
70.97.122.105
70.97.122.106
70.97.122.107
70.97.122.104
70.97.122.108
70.97.122.109
share|improve this question
2  
Are the columns tab-separated? –  Excellll Aug 19 '14 at 18:15
3  
One more question: does the data you want to keep ever include a space? –  Excellll Aug 19 '14 at 18:26
1  
nope i only need the ips –  Bob J Aug 19 '14 at 18:31
20  
Why you want to do that in notepad++? Why column mode is not an option? –  Kamil Aug 19 '14 at 18:36
1  
You could use column mode to delete the second column to the EOL, and then use the Trim Trailing and save to get rid of the whitespace. –  Darthfett Aug 20 '14 at 21:58

11 Answers 11

up vote 54 down vote accepted

If the data in the first column never contains a space, you can use a regular expression find and replace to get what you want.

In regular expression mode, search for:

^([^ ]*).*

And replace with

\1

What this does:

^ indicates that any match should start at the beginning of a line.
([^ ]*) is any expression that does not contain a space. The match is greedy, so this will match everything up to the first space (or the end of the line, whichever comes first).
.* is everything else on the line.

\1 refers to the part of the match inside the parentheses. That is, the entire line is replaced by just the bit from the first column.

share|improve this answer
5  
Nice to know that notepad++ supports regular expressions in search-replace! –  Kamil Aug 19 '14 at 18:37
1  
Regex will do the job for you so long as the data never contains a space. Simpler would be the UNIX 'cut' command but doing UNIX commands under windows is whole 'nother problem. cut is made for this and processes large files quickly, with defined column delimiters or by character-counts. –  Karl Aug 19 '14 at 18:39
31  
This can be done far more simply: replace " .*" (note the leading space) with "" (i.e. nothing) to delete everything after and including the first space. –  Fraxtil Aug 19 '14 at 20:52
2  
@Fraxtil Thanks. You should post that as an answer. You'll get an upvote from me. –  Excellll Aug 19 '14 at 21:11
    
@Excellll alright, done. –  Fraxtil Aug 19 '14 at 21:19

Here's a simpler regular expression you can use to achieve the same effect. Replace

 .*

(note the leading space)

with nothing. This will delete everything after and including the first space. This will work as long as your IP addresses are never prefixed with any whitespace (as is the case in your example).

share|improve this answer
8  
Man, regex is pure magic. I don't think I'll ever grok it :) –  Torben Gundtofte-Bruun Aug 20 '14 at 7:35
13  
Make sure that the flag to have . match newlines is off. –  Taemyr Aug 20 '14 at 9:00
    
@TorbenGundtofte-Bruun regex101.com makes everything 100X easier, regex101.com/r/xF2pM4/1 example using that website using the above example –  Halfwarr Aug 20 '14 at 17:38
3  
In case it's potentially a tab instead of a space, you can use [ \t].* –  Cornstalks Aug 20 '14 at 18:13
4  
@Cornstalks \s.* is shorter. Maybe even use \s+.*, to match an arbitrary amount of whitespace, now that we're coding defensively. –  Anko Aug 22 '14 at 13:32

If you are using Windows and if you don't mind trailing spaces (you can find/replace them afterwards), use the Block Select feature:

  1. Press and Hold the Alt key
  2. Using the mouse, select the portion to delete (the entire block of text)
  3. Release the Alt key
  4. Delete that block of text
  5. Repeat as necessary
share|improve this answer
    
Is that supposed to be the minus "-" key? –  Dracs Aug 19 '14 at 23:11
    
Sorry - I used LT and GT brackets around 'alt' key. Fixed now. –  Reed Shilts Aug 19 '14 at 23:26
10  
You can change it to <kdb>Alt</kbd> and it will format it as a key. –  Dracs Aug 19 '14 at 23:27
    
I've been using Notepad forever....and never knew this feature existed! 1 Bazillion +1!!!!! –  jmstoker Aug 22 '14 at 22:00
    
The OP said: "Column mode is not an option" –  Peter Mortensen Aug 23 '14 at 18:52

A regular expression is quicker, but you can do some really tricky things with macros if it is a more complicated task.

You could record a macro:

  1. Cursor on line 1
  2. Hit Start recording
  3. Press key home
  4. Hold Ctrl while you press key Right arrow (seven times)
  5. Hold Shift while you press key End
  6. Press key Delete
  7. Press key Down arrow
  8. Hit Stop recording

Then play it back:

  1. Hit "Run a macro multiple times"
  2. Type in the lines of the document minus 1, since the first line is complete.
share|improve this answer

Place cursor after 70.97.110.40.

Place cursor

Press Alt, and drag the cursor to right and down to select the unwanted part.

Select

Press Backspace or Delete.

Delete

share|improve this answer
1  
All this time using Notepad++ and I never knew it had a "Block Select Mode" like TextPad. –  Kev Aug 23 '14 at 2:25
    
@Kev: it works the same way in Visual Studio. –  Peter Mortensen Aug 23 '14 at 18:51
1  
The OP said: "Column mode is not an option" –  Peter Mortensen Aug 23 '14 at 18:54
    
@PeterMortensen - re:VS - hell, been using that since 2002 and didn't even know! –  Kev Aug 23 '14 at 22:08

Here are a couple of alternative methods to the given answer.

If you data is fixed width, you can also use the following regular expression in the search:

Find what: ^(.{16}).*$

Replace with: \1

It is great if the data you want to keep does contain a space, as someone mentioned. Additionally, again for fixed width data, you can use Column Mode Editing. It's a neat little feature that allows you to edit multiple lines of data in the same column location. See Column Mode Editing.

It makes mention of arrow keys, but you can also use Page Up/Down for a faster method, as well as End and Home keys. The mouse also works. But you could use this for an ad hoc method of deleting data after a certain point, especially if it is only a few lines. It is also good for copying data, but the way it pastes is a bit odd, so you'd want to get used to that first.

share|improve this answer
1  
Better than selecting it and replacing it with itself would be to use a lookbehind like: (?<=^.{13}).* and replace it with nothing. This will select anything after the first 13 characters. –  Chris Murray Aug 21 '14 at 15:37

Similar to enthdegree:

  1. Place cursor at column 16
  2. Shift + Alt + Page Down
  3. Shift + Alt + End
  4. Delete

If there is a blank line at the end of the file, simply press Up Arrow prior to #3.

It's not perfect, but it's handy.

share|improve this answer
  1. Press ALTwhile using the mouse as a lasso.
  2. Select all you want to remove
  3. Press DELETE
share|improve this answer
    
Assuming the first column lines up nicely, like IP addresses, then this is the quickest way. –  bgStack Aug 20 '14 at 14:46
    
The OP said: "Column mode is not an option" –  Peter Mortensen Aug 23 '14 at 18:53

Here is a visual way:

  • Put cursor at end of an IP address.
  • Alt+Shift+Pg Down
  • Alt+Shift+Right
  • Delete

This is not 'column based.' It only works because your IP addresses all line up.

share|improve this answer
1  
What do you mean by "This is not 'column based.'"? Alt+Shift+Arrow switches to "column mode". –  w3d Aug 20 '14 at 15:27
    
It doesn't respect tab-delineation as a column. It breaks them up into spaces so that each line in the selection has the same # of chars beyond the edge of the selections starting point. –  enthdegree Aug 20 '14 at 15:31

Delete everything after first column in Notepad++:

  1. Selcect the 2nd column : Alt + Drag
  2. For selecting rest columns: simply press Right Arrow
share|improve this answer

In regular expression mode, search for:

\t.*

And replace with

Nothing

share|improve this answer
    
Can you add a sentence or two to explain what this does? Thanks. –  fixer1234 Dec 30 '14 at 21:55
1  
Stack Exchange converts tabs to spaces while displaying, but even in edit mode, the example does not show any tabs. –  Arjan Dec 30 '14 at 22:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.