select a column of data

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
djehres
Posts: 4
Joined: Tue Jan 04, 2011 7:04 pm

select a column of data

Post by djehres »

If I have a data file delimited by | how do I select just the first column of data?

1929393|dafda|d0354
492394|flat|dl303
239095860|daeio|3901

If I have thousands of rows of data like this how do I select and pull just the first column?

thanks.
ACRobin
Posts: 134
Joined: Fri Nov 04, 2005 9:51 pm
Location: Northumberland,UK
Contact:

Post by ACRobin »

There is probably a way of doing what you want with a regular expression, but here is another:

do a find replace on the field separators (the pipe symbols) and replace with tabs (\t) - this should line up your columns.

Use Block Select mode and select the column you want.

cut and paste into a new document.

Job done.

You will need to use a fixed font and in the new document you can set the preferences for the document to get of any trailing tabs and spaces.
ak47wong
Posts: 703
Joined: Tue Aug 12, 2003 9:37 am
Location: Sydney, Australia

Post by ak47wong »

ACRobin's idea works, but needs some tweaking:

Firstly, replacing with "\t" only works if you select the Regular expression check box. Then, if you have POSIX regular expression syntax enabled under Configure->Preferences->Editor, you need to use "\|" as the Find string rather than just "|".

Secondly, you would need to increase the tab spacing to make the columns line up. Under View->Document Properties->Tabulation, set Default tab spacing to a value larger than the length of the longest value in the first column. In the example, "239095860" is the longest value, which is 9 characters in length, so you would need to set the tab spacing to at least 10.

It seems to me that it would be easier just to delete everything after the first delimiter using a Replace operation:

Find what: \|.*
Replace with: (nothing)
Select the Regular expression check box
Click Replace All

This assumes you have POSIX regular expression syntax enabled as described above.
actroid
Posts: 9
Joined: Sun Feb 27, 2011 1:27 pm

Post by actroid »

This work for me thanks.....how about if i would to select second column or the thirth column only ...tq
ak47wong
Posts: 703
Joined: Tue Aug 12, 2003 9:37 am
Location: Sydney, Australia

Post by ak47wong »

You can modify the find and replace operation described above.

To keep just the second column:
Find what: (.*)\|(.*)\|(.*)
Replace with: \2

To keep the third column:
Find what: (.*)\|(.*)\|(.*)
Replace with: \3
runderw
Posts: 3
Joined: Wed May 25, 2011 1:49 am

Post by runderw »

could you show me how to keep column 2 and 3

i try this
Find what: (.*)\|(.*)\|(.*)
Replace with: \2\3

but | also remove i would like keep | after the column 2
ak47wong
Posts: 703
Joined: Tue Aug 12, 2003 9:37 am
Location: Sydney, Australia

Post by ak47wong »

There are a number of ways to do it, but the easiest is just to put the vertical bar back into the replacement expression:

Find what: (.*)\|(.*)\|(.*)
Replace with: \2|\3
Post Reply