Вопрос

I have a collection of data in a CSV file and I want to manipulate it in so that I only use some of the values in it. example I have:

1,2,3,4,5,6
asd,sdf,dfg,fgh,ghj,hjk
asd,sdf,dfg,fgh,ghj,hjk
asd,sdf,dfg,fgh,ghj,hjk
asd,sdf,dfg,fgh,ghj,hjk
asd,sdf,dfg,fgh,ghj,hjk

what I want to do is use only use a few fields and possibly in a different order

1,4,3

I know notepad++ can break up values and rearrange them using \1,\2,ect but I don't know how I would do it for this.

Это было полезно?

Решение 2

This regular expression will match 6 groups of 0+ non-comma characters for each line:

^([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)$

You can then replace with your captured groups like so:

\1,\4,\3

RegEx101


Side note:

Someone correct me if I'm wrong. I've been trying to reduce this down to just one repeated capturing group for legibility, but I can't seem to make it work since it only sees this as one capture group:

^([^,]*,?){6}$

Другие советы

Notepad++ isn't really a spreadsheet, which would be your easiest approach for this kind of edit after importing a .CSV. However it does have some limited column editing features which make this workable. Two steps are required, which are outlined below.

1) Line up your text:

  • a) Highlight all the text.
  • b) Select the TextFX menu,
  • c) then the TextFX Edit sub-menu,
  • d) then the "Line up mulitple lines by (,)" option.

You will now have all your columns aligned on the commas.

2) Delete an individual column:

  • a) Ensure no text is highlighted.
  • b) Hold down the [alt] key while selecting the column you wish to delete with the mouse.
  • c) Press the delete key to delete what you've highlighted.

The above assumes you have the TextFX plugin installed. If I remember right, this comes as standard but if not, you can easily find it and add it from the Plugin Manager.

Here is an example of selecting an aligned column using the alt key and the mouse, taken from the official Notepad++ site: http://notepad-plus-plus.org/features/column-mode-editing.html

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top