Align columns in VI

I have a bunch of rows that I would like to split into two columns, and get data from each column. The data looks something like this:

current_well.well_number
current_well.well_name
current_well.well_type_code
well_location.section
well_location.range

Essentially, I would like to split a row based on a period, turn the data into two columns, and then grab the data for each column. I know this can be done in Excel, but I'm really interested in solving VI for this problem. I know that

%s/\./

will format a string with empty space. But as soon as I have data that looks like this:

current_well    well_number
current_well    well_name
current_well    well_type_code
well_location   section
well_location   range

How do I get all the values ​​for each column so that I can paste it into another application?

+3
source share
11 answers

. , . , , , . , :

lt1tab.value1
gt1tabstop.value2

:

%s/\./\t/g

, tabstop - 8 , :

lt1tab  value1
gt1tabstop    value2

, ( , ). :

%s/^.*\.//

:

value1
value2

.


Vim, unix cut , :

cut -f2 -d. input_file > output_file
+2

Align plugin , Visual Block. :

:%Align \.

:

current_well  . well_number
current_well  . well_name
current_well  . well_type_code
well_location . section
well_location . range

, . :

:%s/\v(.*)\.(.*)/\=printf("%-16s %s", submatch(1), submatch(2))/

:

current_well     well_number
current_well     well_name
current_well     well_type_code
well_location    section
well_location    range

Ctrl-V . , , .

+4

linux

:%!column -s . -t

.

+3

, / Excel . , , , vi. , :

, . , .

, :

:%s/\./^M/

, . .

Go[Esc]
:1

:

:map [Key] mkjddGp'kj

( , , , , , .)

, . , 5 . , !

:

current_well
current_well
current_well
well_location
well_location

well_number
well_name
well_type_code
section
range

, .

+1

:

  • w ( W ) ,
  • CTRL - R CTRL - W

, -.

0

? C-v, , , .

:set guioptions+=a

.

, , . , ?


, (3- ).

, , , . , 15 - . . .

, , , , , .

0

gvim, Ctrl-V Ctrl-G, Ctrl-Q Ctrl-G ( , Windows), .

0

Ctrl V

0

, :

:% s/\./CtrlV-Tab/

CtrlV, .

, , , Excel.

0

, :

%s/./                     /

<c-v>, , , , <, , .. .

, , , : (qq), (f.), space (20i <esc>), (d15|), (j). shift @Q ( 10@q), .:)

0

:

!}awk -F. '{print $1}' >> %

, . L ().
, .

for(i=1;i<=NR;i++);print $2 >> %

L

Delete source lines.
Now you have the first and second parts in two groups.

0
source

Source: https://habr.com/ru/post/1707078/


All Articles