简体   繁体   English

使用awk填充列中的前导零

[英]padding leading zeros in a column using awk

I would like to left pad with "0's" on first column say (width 14) 我想在第一栏上留下垫子“0”,说(宽度14)

input.txt input.txt中
17: gdgdgd
117: aa

Need the out put as below 需要输出如下
00000000000017: gdgdgd 00000000000017:gdgdgd
00000000000117: aa 00000000000117:aa

i have tried the awk -F: '{ printf "%14i: %s\\n", $1,$2 }' input.txt but it's working 我试过awk -F: '{ printf "%14i: %s\\n", $1,$2 }' input.txt但是它正在工作

padding more than %09i Nine is not working 填充超过%09i九不起作用

try 尝试

awk -F: '{ printf "%014i: %s\n", $1,$2 }' input.txt

see here 看到这里

A leading '0' (zero) acts as a flag that indicates that output should be padded with zeros instead of spaces. 前导'0'(零)充当标志,指示输出应填充零而不是空格。 This applies only to the numeric output formats. 这仅适用于数字输出格式。 This flag only has an effect when the field width is wider than the value to print. 仅当字段宽度大于要打印的值时,此标志才有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM