在Vim中或使用sed,awk等将所有行用空格填充到固定宽度 [英] Pad all lines with spaces to a fixed width in Vim or using sed, awk, etc

查看:166
本文介绍了在Vim中或使用sed,awk等将所有行用空格填充到固定宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将文件的每一行填充到一定宽度(例如63个字符宽),并在需要时用空格填充?

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

目前,假设所有行数均少于63个字符.

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

我使用Vim,并且希望有一种在其中执行此操作的方法,在这里我可以选择要应用填充的行,并运行某种printf %63s current_line命令.

I use Vim and would prefer a way to do it there, where I can select the lines I wish to apply the padding to, and run some sort of a printf %63s current_line command.

但是,我当然愿意使用sed,awk或某种Linux工具来完成这项工作.

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

推荐答案

Vim

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

这篇关于在Vim中或使用sed,awk等将所有行用空格填充到固定宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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