Marjer
Marjer

Reputation: 1403

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

Upvotes: 8

Views: 13516

Answers (1)

a5hk
a5hk

Reputation: 7834

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.

Upvotes: 17

Related Questions