简体   繁体   中英

padding leading zeros in a column using awk

I would like to left pad with "0's" on first column say (width 14)

input.txt
17: gdgdgd
117: aa

Need the out put as below
00000000000017: gdgdgd
00000000000117: aa

i have tried the awk -F: '{ printf "%14i: %s\\n", $1,$2 }' input.txt but it's working

padding more than %09i Nine is not working

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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