如何对第一列数据进行零填充

Jon*_*Jon 0 unix perl multiple-columns

我在tab分隔的列中有这样的数据:

1   name1   attribute1
1   name1   attribute2
1   name1   attribute3
31  name2   attribute1
31  name2   attribute2
31  name2   attribute3
444 name3   attribute1
444 name3   attribute2
444 name3   attribute3
Run Code Online (Sandbox Code Playgroud)

我希望这样:

001 name1   attribute1
001 name1   attribute2
001 name1   attribute3
031 name2   attribute1
031 name2   attribute2
031 name2   attribute3
444 name3   attribute1
444 name3   attribute2
444 name3   attribute3
Run Code Online (Sandbox Code Playgroud)

我可以在unix或perl中执行此操作吗?

ike*_*ami 5

perl -i~ -pe's/^(\d+)/sprintf "%03d", $1/e' file
Run Code Online (Sandbox Code Playgroud)

实际上,上述检查超出了它的需要.这是一个更通用的解决方案:

perl -i~ -pe's/^([^\t]*)/sprintf "%03s", $1/e' file
Run Code Online (Sandbox Code Playgroud)