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 would like to keep only the first word of each line within Notepad ++. For an example, please consider the situation where I have these lines

aleag greats broa
abro gdert gfherr httowpw
asteruso dgheur graterf

Want I would like have left is this
aleag
abro
asteruso

How do I do this? Either using notepad++ or something else.

share|improve this question
3  
Notepad++ allows regular expression to find match [ use CTRL+F ]. You can write regular expression to match everything after face space character and replace it with nothing. –  mnmnc Dec 17 '12 at 11:02

4 Answers 4

I've only just looked at a reference sheet, so there's probably a better way to do this, but you could do something like this with the Replace dialog (Ctrl+H):

Find: ([0-9a-zA-Z]*)([0-9a-zA-Z ]*$)
Replace: \1

The way I read it is basically:
[0-9a-zA-Z] : match an alphanumeric character
* : keep matching them
[0-9a-zA-Z ] : match an alphanumeric character or a space
$ : match the end of the line
() : "holds" a match in a variable. The first () holds a match in \1, the second in \2 (which we don't need).

Since the first () is "holding" the match you want, that will be what you are replacing the text with. It does this for each line if you hit Replace All.

wordpad++ find replace

share|improve this answer

As you don't know any languages to program in, you can do this in Excel

Paste each line into Column A.

Then, in column B, paste

=LEFT(A1,SEARCH(" ",A1)-1)

enter image description here

share|improve this answer
    
I am not good with programming languages sir,so something else means any program that i can download and use to do what i need to be done –  Habeeb Dec 17 '12 at 10:51

A similar solution to the one Louis suggested is to again use Regular expression search within Notepad++, with the search parameter:

(^.+?)\s.*$

And replace with:

\1

The advantage/difference of this version over Louis' one is that it will also match first words like Apostrophy's or Colons: or Hyphen-ated where there are non alphanumeric characters.

This matches everything from the start of each line (the ^ symbol means start of line). It finds at least one character (.+? is non-greedy match one or more characters) stopping as soon as it finds a blank (\s is blank/space). It then carries on matching everything else in the line (.* is match zero or more characters), up to the end of the line ($ is end of line).

The \1 will then only keep the section matched within the brackets, I.E. everything before the first space in the line.

N.B. make sure the . matches newline checkbox is unticked, or you will only get the first word in the whole document.

share|improve this answer

An even simpler solution is to use " .*" Just open Notepad++, Choose regular expression's in search and replace, enter the below and then click replace all:

Find:  .*

Note that, the is a space in front of the dot and that replace is blank.

enter image description here

share|improve this answer

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.