我有一堆行,我想分成两列,并从每列获取数据.数据看起来像这样:
current_well.well_number
current_well.well_name
current_well.well_type_code
well_location.section
well_location.range
Run Code Online (Sandbox Code Playgroud)
基本上我想要做的是根据周期分割线,将数据转换为两列,然后获取每列的数据.我知道这可以在Excel中完成,但我真的对这个问题的VI解决方案感兴趣.我知道
%s/\./
Run Code Online (Sandbox Code Playgroud)
将使用空格式格式化字符串.但是,一旦我的数据看起来像:
current_well well_number
current_well well_name
current_well well_type_code
well_location section
well_location range
Run Code Online (Sandbox Code Playgroud)
如何获取每列的所有值,以便将其粘贴到另一个应用程序中?
一种选择是使用此Align插件对句点进行排列,以便您可以更轻松地在可视块模式下选择列.例如,如果你这样做:
:%Align \.
Run Code Online (Sandbox Code Playgroud)
你最终得到:
current_well . well_number
current_well . well_name
current_well . well_type_code
well_location . section
well_location . range
Run Code Online (Sandbox Code Playgroud)
如果您不想使用插件,请尝试使用空格填充列.例如,为您的文字:
:%s/\v(.*)\.(.*)/\=printf("%-16s %s", submatch(1), submatch(2))/
Run Code Online (Sandbox Code Playgroud)
这会让你:
current_well well_number
current_well well_name
current_well well_type_code
well_location section
well_location range
Run Code Online (Sandbox Code Playgroud)
然后,您可以Ctrl-V选择要复制的文本列.只需确保选择宽度超过最宽值的列宽.
我已经多次遇到这个问题了。将点更改为制表符将使它们基本上很好地排列起来,但实际上并非如此。确实,所有列都将从一个制表位开始,但不能保证它们将位于同一个制表位上。例如,如果这是您的原始文本:
lt1tab.value1
gt1tabstop.value2
Run Code Online (Sandbox Code Playgroud)
你也是:
%s/\./\t/g
Run Code Online (Sandbox Code Playgroud)
假设制表位有 8 个空格,您将得到:
lt1tab value1
gt1tabstop value2
Run Code Online (Sandbox Code Playgroud)
您可能想要做的是删除除最后一列(或您想要的任何列)之外的所有内容。例如:
%s/^.*\.//
Run Code Online (Sandbox Code Playgroud)
会给你留下:
value1
value2
Run Code Online (Sandbox Code Playgroud)
您可以轻松复制和粘贴。
如果你不必使用 Vim,你可以使用 unixcut来做你想做的事:
cut -f2 -d. input_file > output_file
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5410 次 |
| 最近记录: |