bash 如何删除vi文件中的列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36879257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to delete columns in vi file?
提问by Jarhead
I have a vi file containing hundreds of lines with the following format
我有一个包含数百行的 vi 文件,格式如下
029.inp.log: SCF Done: E(RHF) = -844.790844670 A.U. after 26 cycles
I want to delete all of the columns (separated by spaces/tabs. got messed up when I pasted it here) other than the first (029.inp.log:) and the fifth (-844.790844670). Can anyone help me?
我想删除除第一列 (029.inp.log:) 和第五列 (-844.790844670) 之外的所有列(由空格/制表符分隔。当我在这里粘贴时搞砸了)。谁能帮我?
回答by shafeeq
Press ctrl+v
for block selection. use h, j, k, l
keys to navigate and press key d
to delete the selected block. The graphical editor like kate
also having capability of the block selection.
按ctrl+v
进行块选择。使用h, j, k, l
键导航并按 键d
删除所选块。图形编辑器kate
还具有块选择功能。
回答by gzh
If you are not confined to vi, shell command is a good choice for this task.
如果您不局限于 vi,shell 命令是执行此任务的不错选择。
cat your_filename | cut -f 1,5 > result_filename
cat your_filename | cut -f 1,5 > result_filename
About rectangle selection in vim, you must guarantee that the field in all lines with the same width.
关于vim中的矩形选择,必须保证所有行中的字段宽度相同。
Perhaps vim command
:%!cut -f1,5
is OK too, but I can not give it a try now.
也许 vim 命令
:%!cut -f1,5
也可以,但我现在不能试一试。