VIM或用sed / awk的/等等 - 所有垫用空格线固定宽度 [英] vim or sed/awk/etc - pad all lines with spaces to fixed width

查看:154
本文介绍了VIM或用sed / awk的/等等 - 所有垫用空格线固定宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能垫文件的每一行有一定的宽度(比如63个字符宽),填充用空格,如果需要的?

现在,我们假设所有的线条都保证少于63个字符。

我使用vim,并会preFER一个办法做到这一点有(有没有某种中的printf%63S current_line 命令?),在那里我可以选择行我想填充申请。

不过,我肯定是要使用SED开放,awk中,或某种Linux的工具来完成这项工作了。

欢呼声。


解决方案

VIM

 :%s的/.*/\\=的printf(% -  63S',子匹配(0))

How can I pad each line of a file to a certain width (say 63 characters wide), padding with spaces if need be?

For now, let's assume all lines are guaranteed to be less than 63 characters.

I use vim and would prefer a way to do it there (is there some sort of printf %63s current_line command?) where I can select the lines I wish to apply the padding to.

However, I'm certainly open to using sed, awk, or some sort of linux tool to do the job too.

cheers.

解决方案

vim

:%s/.*/\=printf('%-63s', submatch(0))

这篇关于VIM或用sed / awk的/等等 - 所有垫用空格线固定宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆