linux - 使用 awk 对齐文本文件中的列?

标签 linux bash awk

awk 是否有助于将“输入”转换为“所需输出”?

输入

testing speed of encryption
test 0 (64 bit key, 16 byte blocks): 2250265 operations in 1 seconds (36004240 bytes)
test 1 (128 bit key, 64 byte blocks): 879149 operations in 1 seconds (56265536 bytes)
test 2 (128 bit key, 256 byte blocks): 258978 operations in 1 seconds (66298368 bytes)
test 3 (128 bit key, 1024 byte blocks): 68218 operations in 1 seconds (69855232 bytes)
test 4 (128 bit key, 8192 byte blocks): 8614 operations in 1 seconds (70565888 bytes)
test 10 (256 bit key, 16 byte blocks): 1790881 operations in 1 seconds (3654096 bytes)

期望的输出

testing speed of encryption
test  0  (64 bit key,   16 byte blocks): 2250265 operations in 1 seconds (36004240 bytes)
test  1 (128 bit key,   64 byte blocks):  879149 operations in 1 seconds (56265536 bytes)
test  2 (128 bit key,  256 byte blocks):  258978 operations in 1 seconds (66298368 bytes)
test  3 (128 bit key, 1024 byte blocks):   68218 operations in 1 seconds (69855232 bytes)
test  4 (128 bit key, 8192 byte blocks):    8614 operations in 1 seconds (70565888 bytes)
test 10 (256 bit key,   16 byte blocks): 1790881 operations in 1 seconds  (3654096 bytes)

最佳答案

使用 column 右对齐的一个技巧是使用 rev:

$ head -1 file; tail -n+2 file | rev | column -t | rev
testing speed of encryption
test   0   (64  bit  key,    16  byte  blocks):  2250265  operations  in  1  seconds  (36004240  bytes)
test   1  (128  bit  key,    64  byte  blocks):   879149  operations  in  1  seconds  (56265536  bytes)
test   2  (128  bit  key,   256  byte  blocks):   258978  operations  in  1  seconds  (66298368  bytes)
test   3  (128  bit  key,  1024  byte  blocks):    68218  operations  in  1  seconds  (69855232  bytes)
test   4  (128  bit  key,  8192  byte  blocks):     8614  operations  in  1  seconds  (70565888  bytes)
test  10  (256  bit  key,    16  byte  blocks):  1790881  operations  in  1  seconds   (3654096  bytes)

关于linux - 使用 awk 对齐文本文件中的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14095011/

相关文章:

linux - sed 匹配以 * 和//开头的行

linux - 如何编写一个名为largest的程序,它可以接受任意数量的参数

linux - 打印最后一个斜杠后的文本

regex - 匹配正则表达式模式后打印行

linux - While 在 bash 脚本中执行循环和变量?

c - "CPU dies"(与硬件无关)是什么意思?

linux - 使用 sed 替换 apache2.conf 文件中代码块内的文本

linux - 如何在 awk 中使用多个定界符?

python - 我可以在 Centos 7 上安装 node.js 18 吗?我还需要安装 python 3 吗?

linux - OSX 和 chroot 无法找到/bin/bash