Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

padding leading zeros in a column using awk

Tags:

unix

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

like image 722
Marjer Avatar asked Apr 23 '14 12:04

Marjer


1 Answers

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.

like image 133
a5hk Avatar answered Oct 06 '22 16:10

a5hk