I have a bunch of lines that I’d like to split into two columns, and get the 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 what I’d like to do is split the line based off of the 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 VIs solution for this problem. I know that
%s/\./
will format the string with empty spaces. But once I have the data looking like:
current_well well_number current_well well_name current_well well_type_code well_location section well_location range
How do I grab all the values for each column so I can paste it into another application?
I’ve run into this problem a number of times. Changing the dots to tabs will line them up mostly nice, but not really. It’s true that all the columns will start on a tabstop, but there’s no guarantee that they’ll be on the same tabstop. For instance, if this was your original text:
and you do:
and assuming a tabstop is 8 spaces, you’ll get:
What you might want to do instead is remove everything but the last column (or whichever column you want). For instance:
will leave you with:
Which you can easily copy and paste.
If you don’t have to use Vim, you can use unix’s
cutto do what you want: